class RSpec::Core::Configuration
def mock_with(framework)
mod_config.custom_setting = true
config.mock_with OtherMockFrameworkAdapter do |mod_config|
it will yield the configuration object to the block e.g.
If the module responds to `configuration` and `mock_with` receives a block,
- called after verify_mocks_for_rspec (even if there are errors)
teardown_mocks_for_rspec
when expectations fail
- called after each example. Framework should raise an exception
verify_mocks_for_rspec
- called before each example
setup_mocks_for_rspec
should adhere to RSpec's mock framework adapter API:
Given a Module, includes that module in every example group. The module
any mocking framework to save a little bit of overhead.
Given `:nothing`, configures no framework. Use this if you don't use
named framework.
Given any of `:rspec`, `:mocha`, `:flexmock`, or `:rr`, configures the
`framework` can be a Symbol or a Module.
Sets the mock framework adapter module.
def mock_with(framework) framework_module = case framework when Module framework when String, Symbol require case framework.to_s when /rspec/i deprecate_unless_mock_adapter_name_is_exact(framework, :rspec) 'rspec/core/mocking/with_rspec' when /mocha/i deprecate_unless_mock_adapter_name_is_exact(framework, :mocha) 'rspec/core/mocking/with_mocha' when /rr/i deprecate_unless_mock_adapter_name_is_exact(framework, :rr) 'rspec/core/mocking/with_rr' when /flexmock/i deprecate_unless_mock_adapter_name_is_exact(framework, :flexmock) 'rspec/core/mocking/with_flexmock' else deprecate_unless_mock_adapter_name_is_exact(framework, :nothing) 'rspec/core/mocking/with_absolutely_nothing' end RSpec::Core::MockFrameworkAdapter end new_name, old_name = [framework_module, @mock_framework].map do |mod| mod.respond_to?(:framework_name) ? mod.framework_name : :unnamed end unless new_name == old_name assert_no_example_groups_defined(:mock_framework) end if block_given? raise "#{framework_module} must respond to `configuration` so that mock_with can yield it." unless framework_module.respond_to?(:configuration) yield framework_module.configuration end @mock_framework = framework_module end