Method: Spec::Runner::Configuration#mock_with

Defined in:
lib/spec/runner/configuration.rb

#mock_with(mock_framework) ⇒ Object

Chooses what mock framework to use. Example:

Spec::Runner.configure do |config|
  config.mock_with :rspec, :mocha, :flexmock, or :rr
end

To use any other mock framework, you’ll have to provide your own adapter. This is simply a module that responds to the following methods:

setup_mocks_for_rspec
verify_mocks_for_rspec
teardown_mocks_for_rspec.

These are your hooks into the lifecycle of a given example. RSpec will call setup_mocks_for_rspec before running anything else in each Example. After executing the #after methods, RSpec will then call verify_mocks_for_rspec and teardown_mocks_for_rspec (this is guaranteed to run even if there are failures in verify_mocks_for_rspec).

Once you’ve defined this module, you can pass that to mock_with:

Spec::Runner.configure do |config|
  config.mock_with MyMockFrameworkAdapter
end

33
34
35
36
37
38
39
40
# File 'lib/spec/runner/configuration.rb', line 33

def mock_with(mock_framework)
  @mock_framework = case mock_framework
  when Symbol
    mock_framework_path(mock_framework.to_s)
  else
    mock_framework
  end
end