Module FlexMock::TestCase
In: lib/flexmock.rb

Test::Unit::TestCase Integration.

Include this module in any TestCase class in a Test::Unit test suite 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.

Note: If you define a teardown method in the test case, dont’ forget to invoke the super method! Failure to invoke super will cause all mocks to not be verified.

Methods

Included Modules

ArgumentTypes

Public Instance methods

Create a FlexMock object with the given name. Mocks created with this method will be automatically verify during teardown (assuming the the flexmock teardown isn‘t overridden).

If a block is given, then the mock object is passed to the block and may be configured in the block.

Do the flexmock specific teardown stuff.

Stub the given object by overriding the behavior of individual methods. The stub object returned will respond to the should_receive method, just like normal stubs. Singleton methods cannot be stubbed.

Example: Stub out DBI to return a fake db connection.

  flexstub(DBI).should_receive(:connect).and_return {
    fake_db = flexmock("db connection")
    fake_db.should_receive(:select_all).and_return(...)
    fake_db
  }

Intercept the named class in the target class for the duration of the test. Class interception is very simple-minded and has a number of restrictions. First, the intercepted class must be reference in the tested class via a simple constant name (e.g. no scoped names using "::") that is not directly defined in the class itself. After the test, a proxy class constant will be left behind that will forward all calls to the original class.

Usage:

  intercept(SomeClass).in(ClassBeingTested).with(MockClass)
  intercept(SomeClass).with(MockClass).in(ClassBeingTested)

Teardown the test case, verifying any mocks that might have been defined in this test case.

[Validate]