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