Class: FlexMock

Class | FlexMock
In: | lib/flexmock/argument_matchers.rb lib/flexmock/argument_types.rb lib/flexmock/composite.rb lib/flexmock/core.rb lib/flexmock/core_class_methods.rb lib/flexmock/default_framework_adapter.rb lib/flexmock/deprecated_methods.rb lib/flexmock/errors.rb lib/flexmock/expectation.rb lib/flexmock/expectation_director.rb lib/flexmock/mock_container.rb lib/flexmock/ordering.rb lib/flexmock/partial_mock.rb lib/flexmock/rails/view_mocking.rb lib/flexmock/recorder.rb lib/flexmock/rspec.rb lib/flexmock/test_unit_integration.rb lib/flexmock/undefined.rb lib/flexmock/validators.rb
Parent: | Object

     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

by_default flexmock_teardown flexmock_verify inspect method method_missing mock_ignore_missing new respond_to? should_expect should_ignore_missing should_receive undefined use

### Included Modules

Ordering

### 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

### External Aliases

respond_to? | -> | flexmock_respond_to?
| Save the original definition of respond_to? for use a bit later.

### Attributes

flexmock_container | [RW] |
flexmock_name | [R] |
framework_adapter | [R] |

### 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.

undefined()

Undefined is normally available as FlexMock.undefined

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.

### Public Instance methods

by_default()
flexmock_teardown()

Teardown and infrastructure setup for this mock.

flexmock_verify()

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

inspect()

Return the inspection string for a mock.

method(sym)

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

method_missing(sym, *args, &block)

Handle missing methods by attempting to look up a handler.

mock_ignore_missing()

Alias for should_ignore_missing

respond_to?(sym, *args)

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

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

should_ignore_missing()

Ignore all undefined (missing) method calls.

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.

[Validate]