Expectations on mocks with a base class can only be defined on methods supported by the base class. Attempting to add an stub to a method not defined on the base class will cause the expectation to be wrapped in an ExplicitNeeded wrapper. The wrapper will throw an exception unless the explicit method is immediately called on the expectation.
# File lib/flexmock/explicit_needed.rb, line 24 def explicit? @explicit end
# File lib/flexmock/explicit_needed.rb, line 19 def explicitly @explicit = true self end
# File lib/flexmock/explicit_needed.rb, line 28 def method_missing(sym, *args, &block) if explicit? @expectation.send(sym, *args, &block) else fail NoMethodError, "Cannot stub methods not defined by the base class\n" + " Method: #{@method_name}\n" + " Base Class: #{@base_class}\n" + " (Use 'explicitly' to override)" end end
Generated with the Darkfish Rdoc Generator 2.