Class: RSpec::Mocks::DirectObjectReference
- Inherits:
-
Object
- Object
- RSpec::Mocks::DirectObjectReference
- Defined in:
- lib/rspec/mocks/object_reference.rb
Overview
An implementation of rspec-mocks' reference interface. Used when an object is passed to ExampleMethods#object_double, or an anonymous class or module is passed to ExampleMethods#instance_double or ExampleMethods#class_double. Represents a reference to that object.
Instance Method Summary collapse
-
#const_to_replace ⇒ Object
Defined for interface parity with the other object reference implementations.
-
#defined? ⇒ true
Always returns true for an object as the class is defined.
-
#description ⇒ String
The object's description (via
#inspect
). -
#initialize(object) ⇒ DirectObjectReference
constructor
A new instance of DirectObjectReference.
-
#target ⇒ Object
The target of the verifying double (the object itself).
-
#when_loaded {|Object| ... } ⇒ Object
Yields if the reference target is loaded, providing a generic mechanism to optionally run a bit of code only when a reference's target is loaded.
Constructor Details
#initialize(object) ⇒ DirectObjectReference
Returns a new instance of DirectObjectReference.
58 59 60 |
# File 'lib/rspec/mocks/object_reference.rb', line 58 def initialize(object) @object = object end |
Instance Method Details
#const_to_replace ⇒ Object
Defined for interface parity with the other object reference implementations. Raises an ArgumentError
to indicate that as_stubbed_const
is invalid when passing an object argument to object_double
.
70 71 72 73 |
# File 'lib/rspec/mocks/object_reference.rb', line 70 def const_to_replace raise ArgumentError, "Can not perform constant replacement with an anonymous object." end |
#defined? ⇒ true
Always returns true for an object as the class is defined.
85 86 87 |
# File 'lib/rspec/mocks/object_reference.rb', line 85 def defined? true end |
#description ⇒ String
Returns the object's description (via #inspect
).
63 64 65 |
# File 'lib/rspec/mocks/object_reference.rb', line 63 def description @object.inspect end |
#target ⇒ Object
The target of the verifying double (the object itself).
78 79 80 |
# File 'lib/rspec/mocks/object_reference.rb', line 78 def target @object end |
#when_loaded {|Object| ... } ⇒ Object
Yields if the reference target is loaded, providing a generic mechanism to optionally run a bit of code only when a reference's target is loaded.
This specific implementation always yields because direct references are always loaded.
97 98 99 |
# File 'lib/rspec/mocks/object_reference.rb', line 97 def when_loaded yield @object end |