Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / doc / src / documentation / mocks / other_frameworks.page
blob14f6cad0fbb1c0f9eb52e97c7c54be9ee472ad0e
1 ---
2 title: Other Mock/Stub Frameworks
3 ---
4 h2. Other Mock/Stub Frameworks
6 If you prefer to use a mocking framework other than RSpec's built in framework, you
7 can do this quite simply. RSpec currently supports use of the following frameworks
8 out of the box (in alphabetical order):
10 * "flexmock":http://flexmock.rubyforge.org/
11 * "mocha":http://mocha.rubyforge.org
12 * "rr":http://rubyforge.org/projects/pivotalrb/
14 RSpec supports use of a single framework per project, because these frameworks (including)
15 RSpec's own, tend to add methods to Object that might or might not work well together. To
16 choose a mock framework other than rspec, simply add the following to spec/spec_helper.rb
17 (or any file that gets loaded when you run your examples):
19 <ruby>
20 Spec::Runner.configure do |config|
21   config.mock_with :rr
22 end
23 </ruby>
25 Valid options are <code>:flexmock</code>, <code>:mocha</code>, <code>:rspec</code> (of course),
26 and <code>:rr</code>.
28 h2. Even more "other" frameworks
30 If you have a different framework that is not supported directly by RSpec, you can easily
31 choose that framework instead by creating an adapter and telling RSpec where to find it.
32 Here is RSpec's own adapter as an example:
34 <ruby file="../rspec/plugins/mock_frameworks/rspec.rb"/>
36 This file must require any libraries or resources that implement the framework, and then define
37 a <code>Spec::Plugins::MockFramework</code> module with the following methods:
39 * <code>setup_mocks_for_rspec</code> is called before each example is run.
40 * <code>verify_mocks_for_rspec</code> is called after each example is run. Use this if you want
41 RSpec to automatically verify your mocks after each example. You must supply this method either
42 way, but you can leave it empty if your framework doesn't support auto-verification.
43 * <code>teardown_mocks_for_rspec</code> is guaranteed to be run after each example even when there
44 are errors. Use this to ensure that there is no state shared across example, clearing out changes
45 to static resources like class-level mock expectations, etc.
47 Once you have defined your adapter, you can then tell RSpec to use your adapter like so:
49 <ruby>
50 Spec::Runner.configure do |config|
51   config.mock_with '/path/to/my/adapater.rb'
52 end
53 </ruby>