Module: FlexMock::MockContainer

### Home Classes Methods

### In Files

- lib/flexmock/mock_container.rb

### Methods

- #flexmock
- #flexmock_close
- #flexmock_created_mocks
- #flexmock_remember
- #flexmock_teardown
- #flexmock_verify
- #flexstub

### Included Modules

- FlexMock::Ordering

### Files

- CHANGES
- GoogleExample.rdoc
- rspec_examples_spec.rdoc
- test_unit_examples_test.rdoc
- index.rdoc
- flexmock-0.4.0.rdoc
- flexmock-0.4.1.rdoc
- flexmock-0.4.2.rdoc
- flexmock-0.4.3.rdoc
- flexmock-0.5.0.rdoc
- flexmock-0.5.1.rdoc
- flexmock-0.6.0.rdoc
- flexmock-0.6.1.rdoc
- flexmock-0.6.2.rdoc
- flexmock-0.6.3.rdoc
- flexmock-0.6.4.rdoc
- flexmock-0.7.0.rdoc
- flexmock-0.7.1.rdoc
- flexmock-0.8.0.rdoc
- flexmock-0.8.2.rdoc
- flexmock-0.8.3.rdoc
- flexmock-0.8.4.rdoc
- flexmock-0.8.5.rdoc
- flexmock-0.9.0.rdoc
- flexmock-1.0.0.rdoc
- flexmock-1.0.3.rdoc
- flexmock-1.0.4.rdoc
- flexmock-1.1.0.rdoc
- flexmock-1.2.0.rdoc
- flexmock-1.3.0.rdoc
- flexmock-1.3.1.rdoc

### Class/Module Index

Quicksearch

- FlexMock
- FlexMock::AnyMatcher
- FlexMock::ArgumentMatching
- FlexMock::ArgumentTypes
- FlexMock::AtLeastCountValidator
- FlexMock::AtMostCountValidator
- FlexMock::CallValidator
- FlexMock::CompositeExpectation
- FlexMock::CountValidator
- FlexMock::DefaultFrameworkAdapter
- FlexMock::DefaultFrameworkAdapter::AssertionFailedError
- FlexMock::DuckMatcher
- FlexMock::EqualMatcher
- FlexMock::ExactCountValidator
- FlexMock::Expectation
- FlexMock::ExpectationBuilder
- FlexMock::ExpectationDirector
- FlexMock::ExpectationRecorder
- FlexMock::ExplicitNeeded
- FlexMock::ExtensionRegistry
- FlexMock::Extensions
- FlexMock::Extensions::ActiveRecordModel
- FlexMock::GenericTestCase
- FlexMock::HashMatcher
- FlexMock::MockBuilder
- FlexMock::MockContainer
- FlexMock::MockError
- FlexMock::OptionalProcMatcher
- FlexMock::Ordering
- FlexMock::PartialMockProxy
- FlexMock::ProcMatcher
- FlexMock::RSpecFrameworkAdapter
- FlexMock::RSpecFrameworkAdapter::AssertionFailedError
- FlexMock::RSpecMatchers
- FlexMock::RSpecMatchers::HaveReceived
- FlexMock::Recorder
- FlexMock::SpyDescribers
- FlexMock::TestCase
- FlexMock::TestUnitAssertions
- FlexMock::TestUnitFrameworkAdapter
- FlexMock::Undefined
- FlexMock::UsageError
- FlexMock::UseContainer
- FlexMock::Version
- MiniTest
- MiniTest::Unit
- MiniTest::Unit::TestCase
- Test
- Test::Unit
- Test::Unit::TestCase
- Class
- Module
- Object
- Symbol

No matching classes.

# FlexMock::MockContainer

Mock container methods

Include this module in to get integration with FlexMock. When this module is included, mocks may be created with a simple call to the `flexmock` method. Mocks created with via the method call will automatically be verified in the teardown of the test case.

### Public Instance Methods

flexmock() { |mock| ... } click to toggle source
flexmock(name) { |mock| ... }
flexmock(expect_hash) { |mock| ... }
flexmock(name, expect_hash) { |mock| ... }
flexmock(real_object) { |mock| ... }
flexmock(real_object, name) { |mock| ... }
flexmock(real_object, name, expect_hash) { |mock| ... }
flexmock(:base, string, name, expect_hash) { |mock| ... }

Create a mocking object in the FlexMock framework. The `flexmock` method has a number of options available, depending on just what kind of mocking object your require. Mocks created via `flexmock` will be automatically verify during the teardown phase of your test framework.

Note: A plain flexmock() call without a block will return the mock object (the object that interprets `should_receive` and its brethern). A flexmock() call that includes a block will return the domain objects (the object that will interpret domain messages) since the mock will be passed to the block for configuration. With regular mocks, this distinction is unimportant because the mock object and the domain object are the same object. However, with partial mocks, the mock object is separation from the domain object. Keep that distinciton in mind.

name | Name of the mock object. If no name is given, "unknown" is used for full mocks and "flexmock(real_object)" is used for partial mocks.
expect_hash | Hash table of method names and values. Each method/value pair is used to setup a simple expectation so that if the mock object receives a message matching an entry in the table, it returns the associated value. No argument our call count constraints are added. Using an expect_hash is identical to calling:
    mock.should_receive(method_name).and_return(value)
for each of the method/value pairs in the hash.
real_object | If a real object is given, then a partial mock is constructed using the real_object as a base. Partial mocks (formally referred to as stubs) behave as a mock object when an expectation is matched, and otherwise will behave like the original object. This is useful when you want to use a real object for testing, but need to mock out just one or two methods.
:base | Forces the following argument to be used as the base of a partial mock object. This explicit tag is only needed if you want to use a string or a symbol as the mock base (string and symbols would normally be interpretted as the mock name).
&block | If a block is given, then the mock object is passed to the block and expectations may be configured within the block. When a block is given for a partial mock, flexmock will return the domain object rather than the mock object.

    # File lib/flexmock/mock_container.rb, line 120
    def flexmock(*args, &block)
      location = caller.first
      @flexmock_worker ||= MockBuilder.new(self)
      @flexmock_worker.define_a_mock(location, *args, &block)
    end

Also aliased as: flexstub
flexmock_close() click to toggle source

Close all the mock objects in the container. Closing a mock object restores any original behavior that was displaced by the mock.

    # File lib/flexmock/mock_container.rb, line 52
    def flexmock_close
      flexmock_created_mocks.each do |m|
        m.flexmock_teardown
      end
      @flexmock_created_mocks = []
    end

flexmock_created_mocks() click to toggle source

List of mocks created in this container

    # File lib/flexmock/mock_container.rb, line 46
    def flexmock_created_mocks
      @flexmock_created_mocks ||= []
    end

flexmock_remember(mocking_object) click to toggle source

Remember the mock object / stub in the mock container.

    # File lib/flexmock/mock_container.rb, line 128
    def flexmock_remember(mocking_object)
      @flexmock_created_mocks ||= []
      @flexmock_created_mocks << mocking_object
      mocking_object.flexmock_container = self
      mocking_object
    end

flexmock_teardown() click to toggle source

Do the flexmock specific teardown stuff. If you need finer control, you can use either `flexmock_verify` or `flexmock_close`.

    # File lib/flexmock/mock_container.rb, line 32
    def flexmock_teardown
      flexmock_verify unless flexmock_test_has_failed?
    ensure
      flexmock_close
    end

flexmock_verify() click to toggle source

Perform verification on all mocks in the container.

    # File lib/flexmock/mock_container.rb, line 39
    def flexmock_verify
      flexmock_created_mocks.each do |m|
        m.flexmock_verify
      end
    end

flexstub(*args, &block) click to toggle source
Alias for: flexmock

[Validate]

Generated with the Darkfish Rdoc Generator 2.