Module: RSpec::Mocks
Overview
Contains top-level utility methods. While this contains a few public methods, these are not generally meant to be called from a test or example. They exist primarily for integration with test frameworks (such as rspec-core).
Constant Summary
-
CannotSupportArgMutationsError =
Class.new(StandardError)
-
DEFAULT_CALLBACK_INVOCATION_STRATEGY =
Internal use only
# File 'rspec-mocks/lib/rspec/mocks/verifying_proxy.rb', line 104CallbackInvocationStrategy.new
-
ExpiredTestDoubleError =
Raised when a test double is used after it has been torn down (typically at the end of an rspec-core example).
Class.new(MockExpectationError)
-
IGNORED_BACKTRACE_LINE =
Internal use only
# File 'rspec-mocks/lib/rspec/mocks.rb', line 112'this backtrace line is ignored'
-
MockExpectationAlreadyInvokedError =
Raised when an expectation customization method (e.g.
with
,and_return
) is called on a message expectation which has already been invoked.Class.new(Exception)
-
MockExpectationError =
Raised when a message expectation is not satisfied.
::Minitest::Assertion
-
NegationUnsupportedError =
Internal use only
# File 'rspec-mocks/lib/rspec/mocks/error_generator.rb', line 31Class.new(StandardError)
-
OutsideOfExampleError =
Raised when doubles or partial doubles are used outside of the per-test lifecycle.
Class.new(StandardError)
-
UnsupportedMatcherError =
Internal use only
# File 'rspec-mocks/lib/rspec/mocks/error_generator.rb', line 29Class.new(StandardError)
-
VerifyingDoubleNotDefinedError =
Internal use only
# File 'rspec-mocks/lib/rspec/mocks/error_generator.rb', line 33Class.new(StandardError)
Class Attribute Summary
- .space readonly Internal use only Internal use only
Class Method Summary
-
.allow_message(subject, message, opts = {}) { ... }
Adds an allowance (stub) on
subject
-
.configuration
Mocks
specific configuration, as distinct from configuration which is core::RSpec
configuration. - .error_generator Internal use only Internal use only
-
.expect_message(subject, message, opts = {}) { ... }
Sets a message expectation on
subject
. -
.setup
Performs per-test/example setup.
-
.teardown
Cleans up all test double state (including any methods that were redefined on partial doubles).
-
.verify
Verifies any message expectations that were set during the test or example.
-
.with_temporary_scope ⇒ Object
Call the passed block and verify mocks after it has executed.
Class Attribute Details
.space (readonly)
# File 'rspec-mocks/lib/rspec/mocks.rb', line 106
attr_reader :space
Class Method Details
.allow_message(subject, message, opts = {}) { ... }
Adds an allowance (stub) on subject
# File 'rspec-mocks/lib/rspec/mocks.rb', line 69
def self. (subject, , opts={}, &block) space.proxy_for(subject).add_stub(, opts, &block) end
.configuration
Mocks
specific configuration, as distinct from RSpec.configuration which is core ::RSpec
configuration.
# File 'rspec-mocks/lib/rspec/mocks/configuration.rb', line 206
def self.configuration @configuration ||= Configuration.new end
.error_generator
# File 'rspec-mocks/lib/rspec/mocks/error_generator.rb', line 386
def self.error_generator @error_generator ||= ErrorGenerator.new end
.expect_message(subject, message, opts = {}) { ... }
Sets a message expectation on subject
.
# File 'rspec-mocks/lib/rspec/mocks.rb', line 84
def self. (subject, , opts={}, &block) space.proxy_for(subject). (, opts, &block) end
.setup
Performs per-test/example setup. This should be called before an test or example begins.
# File 'rspec-mocks/lib/rspec/mocks.rb', line 38
def self.setup @space_stack << (@space = space.new_scope) end
.teardown
Cleans up all test double state (including any methods that were redefined on partial doubles). This must be called after each example, even if an error was raised during the example.
# File 'rspec-mocks/lib/rspec/mocks.rb', line 51
def self.teardown space.reset_all @space_stack.pop @space = @space_stack.last || @root_space end
.verify
Verifies any message expectations that were set during the test or example. This should be called at the end of an example.
# File 'rspec-mocks/lib/rspec/mocks.rb', line 44
def self.verify space.verify_all end
.with_temporary_scope ⇒ Object
Call the passed block and verify mocks after it has executed. This allows mock usage in arbitrary places, such as a ‘before(:all)` hook.