Permission is granted for use, copying, modification, distribution,
 and distribution of modified versions of this work as long as the
 above copyright notice is included.

+++

Methods
Included Modules
Classes and Modules
Module FlexMock::ArgumentTypes
Module FlexMock::MockContainer
Module FlexMock::Ordering
Module FlexMock::TestCase
Class FlexMock::AnyMatcher
Class FlexMock::AtLeastCountValidator
Class FlexMock::AtMostCountValidator
Class FlexMock::CompositeExpectation
Class FlexMock::CountValidator
Class FlexMock::DefaultFrameworkAdapter
Class FlexMock::EqualMatcher
Class FlexMock::ExactCountValidator
Class FlexMock::Expectation
Class FlexMock::ExpectationDirector
Class FlexMock::ExpectationRecorder
Class FlexMock::MockContainerHelper
Class FlexMock::MockError
Class FlexMock::PartialMockProxy
Class FlexMock::ProcMatcher
Class FlexMock::RSpecFrameworkAdapter
Class FlexMock::Recorder
Class FlexMock::TestUnitFrameworkAdapter
Class FlexMock::Undefined
Class FlexMock::UsageError
Class FlexMock::UseContainer
Constants
ANY = AnyMatcher.new
ContainerHelper = MockContainerHelper.new
Attributes
[RW] flexmock_container
[R] flexmock_name
[R] framework_adapter
Public Class methods
new(name="unknown", container=nil)

Create a FlexMock object with the given name. The name is used in error messages. If no container is given, create a new, one-off container for this mock.

    # File lib/flexmock/core.rb, line 55
55:   def initialize(name="unknown", container=nil)
56:     @flexmock_name = name
57:     @expectations = Hash.new
58:     @ignore_missing = false
59:     @verified = false
60:     container = UseContainer.new if container.nil?
61:     container.flexmock_remember(self)
62:   end
undefined()

Undefined is normally available as FlexMock.undefined

    # File lib/flexmock/undefined.rb, line 43
43:   def self.undefined
44:     @undefined
45:   end
use(*names) {|*mocks| ...}

Class method to make sure that verify is called at the end of a test. One mock object will be created for each name given to the use method. The mocks will be passed to the block as arguments. If no names are given, then a single anonymous mock object will be created.

At the end of the use block, each mock object will be verified to make sure the proper number of calls have been made.

Usage:

  FlexMock.use("name") do |mock|    # Creates a mock named "name"
    mock.should_receive(:meth).
      returns(0).once
  end                               # mock is verified here

NOTE: If you include FlexMock::TestCase into your test case file, you can create mocks that will be automatically verified in the test teardown by using the flexmock method.

    # File lib/flexmock/core_class_methods.rb, line 39
39:     def use(*names)
40:       names = ["unknown"] if names.empty?
41:       container = UseContainer.new
42:       mocks = names.collect { |n| container.flexmock(n) }
43:       yield(*mocks)
44:     rescue Exception => ex
45:       container.got_exception = true
46:       raise
47:     ensure
48:       container.flexmock_teardown
49:     end
Public Instance methods
by_default()
    # File lib/flexmock/core.rb, line 91
91:   def by_default
92:     @last_expectation.by_default
93:     self
94:   end
flexmock_teardown()

Teardown and infrastructure setup for this mock.

    # File lib/flexmock/core.rb, line 82
82:   def flexmock_teardown
83:   end
flexmock_verify()

Verify that each method that had an explicit expected count was actually called that many times.

    # File lib/flexmock/core.rb, line 71
71:   def flexmock_verify
72:     return if @verified
73:     @verified = true
74:     flexmock_wrap do
75:       @expectations.each do |sym, handler|
76:         handler.flexmock_verify
77:       end
78:     end
79:   end
inspect()

Return the inspection string for a mock.

    # File lib/flexmock/core.rb, line 65
65:   def inspect
66:     "<FlexMock:#{flexmock_name}>"
67:   end
method(sym)

Override the built-in method to include the mocked methods.

     # File lib/flexmock/core.rb, line 130
130:   def method(sym)
131:     @expectations[sym] || super
132:   rescue NameError => ex
133:     if @ignore_missing
134:       proc { FlexMock.undefined }
135:     else
136:       raise ex
137:     end
138:   end
method_missing(sym, *args, &block)

Handle missing methods by attempting to look up a handler.

     # File lib/flexmock/core.rb, line 97
 97:   def method_missing(sym, *args, &block)
 98:     flexmock_wrap do
 99:       if handler = @expectations[sym]
100:         args << block  if block_given?
101:         handler.call(*args)
102:       elsif @ignore_missing
103:         FlexMock.undefined
104:       else
105:         super(sym, *args, &block)
106:       end
107:     end
108:   end
mock_ignore_missing()
respond_to?(sym, *args)

Override the built-in respond_to? to include the mocked methods.

     # File lib/flexmock/core.rb, line 114
114:   def respond_to?(sym, *args)
115:     super || (@expectations[sym] ? true : @ignore_missing)
116:   end
should_expect() {|Recorder.new(self)| ...}

Declare that the mock object should expect methods by providing a recorder for the methods and having the user invoke the expected methods in a block. Further expectations may be applied the result of the recording call.

Example Usage:

  mock.should_expect do |record|
    record.add(Integer, 4) { |a, b|
      a + b
    }.at_least.once
     # File lib/flexmock/core.rb, line 182
182:   def should_expect
183:     yield Recorder.new(self)
184:   end
should_ignore_missing()

Ignore all undefined (missing) method calls.

This method is also aliased as mock_ignore_missing
    # File lib/flexmock/core.rb, line 86
86:   def should_ignore_missing
87:     @ignore_missing = true
88:   end
mock.should_receive(:method_name)
mock.should_receive(:method1, method2, ...)
mock.should_receive(:meth1 => result1, :meth2 => result2, ...)

Declare that the mock object should receive a message with the given name.

If more than one method name is given, then the mock object should expect to receive all the listed melthods. If a hash of method name/value pairs is given, then the each method will return the associated result. Any expectations applied to the result of should_receive will be applied to all the methods defined in the argument list.

An expectation object for the method name is returned as the result of this method. Further expectation constraints can be added by chaining to the result.

See Expectation for a list of declarators that can be used.

     # File lib/flexmock/core.rb, line 159
159:   def should_receive(*args)
160:     @last_expectation = ContainerHelper.parse_should_args(self, args) do |sym|
161:       @expectations[sym] ||= ExpectationDirector.new(sym)
162:       result = Expectation.new(self, sym)
163:       @expectations[sym] << result
164:       override_existing_method(sym) if flexmock_respond_to?(sym)
165:       result
166:     end
167:     @last_expectation
168:   end