Module: RSpec::Mocks::ExampleMethods
- Includes:
- ArgumentMatchers
- Defined in:
- lib/rspec/mocks/example_methods.rb
Defined Under Namespace
Modules: ExpectHost
Instance Method Summary collapse
-
#allow_message_expectations_on_nil ⇒ Object
Disables warning messages about expectations being set on nil.
-
#double(*args) ⇒ Mock
Constructs an instance of RSpec::Mocks::Mock configured with an optional name, used for reporting in failure messages, and an optional hash of method/return-value pairs.
-
#have_received(method_name) ⇒ Object
Verifies that the given object received the expected message during the course of the test.
-
#hide_const(constant_name) ⇒ Object
Hides the named constant with the given value.
-
#mock(*args) ⇒ Object
Deprecated: Use double.
-
#stub(*args) ⇒ Object
Deprecated: Use double.
-
#stub_const(constant_name, value, options = {}) ⇒ Object
Stubs the named constant with the given value.
Methods included from ArgumentMatchers
#any_args, #anything, #boolean, #duck_type, #hash_excluding, #hash_including, #instance_of, #kind_of, #no_args
Instance Method Details
#allow_message_expectations_on_nil ⇒ Object
Disables warning messages about expectations being set on nil.
By default warning messages are issued when expectations are set on nil. This is to prevent false-positives and to catch potential bugs early on.
51 52 53 |
# File 'lib/rspec/mocks/example_methods.rb', line 51 def RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false end |
#double ⇒ Mock #double(name) ⇒ Mock #double(stubs) ⇒ Mock #double(name, stubs) ⇒ Mock
Constructs an instance of RSpec::Mocks::Mock configured with an optional name, used for reporting in failure messages, and an optional hash of method/return-value pairs.
30 31 32 |
# File 'lib/rspec/mocks/example_methods.rb', line 30 def double(*args) declare_double('Double', *args) end |
#have_received(method_name) ⇒ Object
Verifies that the given object received the expected message during the course of the test. The method must have previously been stubbed in order for messages to be verified.
Stubbing and verifying messages received in this way implements the Test Spy pattern.
130 131 132 |
# File 'lib/rspec/mocks/example_methods.rb', line 130 def have_received(method_name) Matchers::HaveReceived.new(method_name) end |
#hide_const(constant_name) ⇒ Object
Hides the named constant with the given value. The constant will be undefined for the duration of the test.
Like method stubs, the constant will be restored to its original value when the example completes.
108 109 110 |
# File 'lib/rspec/mocks/example_methods.rb', line 108 def hide_const(constant_name) ConstantMutator.hide(constant_name) end |
#mock(*args) ⇒ Object
Deprecated: Use double.
35 36 37 38 |
# File 'lib/rspec/mocks/example_methods.rb', line 35 def mock(*args) RSpec.deprecate "mock", :replacement => "double" declare_double('Mock', *args) end |
#stub(*args) ⇒ Object
Deprecated: Use double.
41 42 43 44 |
# File 'lib/rspec/mocks/example_methods.rb', line 41 def stub(*args) RSpec.deprecate "stub", :replacement => "double" declare_double('Stub', *args) end |
#stub_const(constant_name, value, options = {}) ⇒ Object
Stubs the named constant with the given value. Like method stubs, the constant will be restored to its original value (or lack of one, if it was undefined) when the example completes.
92 93 94 |
# File 'lib/rspec/mocks/example_methods.rb', line 92 def stub_const(constant_name, value, = {}) ConstantMutator.stub(constant_name, value, ) end |