class RSpec::Core::Configuration
def mock_with(framework)
mod_config.custom_setting = true
config.mock_with OtherMockFrameworkAdapter do |mod_config|
block, it will yield the configuration object to the block e.g.
If the module responds to `configuration` and `mock_with` receives a
- called after verify_mocks_for_rspec (even if there are errors)
teardown_mocks_for_rspec
Framework should raise an exception when expectations fail
- called after each example if the example hasn't yet failed.
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 = if framework.is_a?(Module) framework else const_name = MOCKING_ADAPTERS.fetch(framework) do raise ArgumentError, "Unknown mocking framework: #{framework.inspect}. " \ "Pass a module or one of #{MOCKING_ADAPTERS.keys.inspect}" end RSpec::Support.require_rspec_core "mocking_adapters/#{const_name.to_s.downcase}" RSpec::Core::MockingAdapters.const_get(const_name) 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