Class FlexMock
In: lib/flexmock/deprecated_methods.rb
lib/flexmock/mock_container.rb
lib/flexmock/core_class_methods.rb
lib/flexmock/composite.rb
lib/flexmock/partial_mock.rb
lib/flexmock/rspec.rb
lib/flexmock/validators.rb
lib/flexmock/argument_matchers.rb
lib/flexmock/test_unit_integration.rb
lib/flexmock/default_framework_adapter.rb
lib/flexmock/errors.rb
lib/flexmock/core.rb
lib/flexmock/recorder.rb
lib/flexmock/expectation.rb
lib/flexmock/expectation_director.rb
lib/flexmock/argument_types.rb
lib/flexmock/undefined.rb
lib/flexmock/rails/view_mocking.rb
lib/flexmock/ordering.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

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::DuckMatcher
Class FlexMock::EqualMatcher
Class FlexMock::ExactCountValidator
Class FlexMock::Expectation
Class FlexMock::ExpectationDirector
Class FlexMock::ExpectationRecorder
Class FlexMock::HashMatcher
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

ContainerHelper = MockContainerHelper.new
SpecModule = RSpec
SpecModule = Spec
ANY = AnyMatcher.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

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 is normally available as FlexMock.undefined

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

Teardown and infrastructure setup for this mock.

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

Return the inspection string for a mock.

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

Handle missing methods by attempting to look up a handler.

mock_ignore_missing()

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

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

Ignore all undefined (missing) method calls.

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]