Class: RSpec::Mocks::NamedObjectReference
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-mocks/lib/rspec/mocks/object_reference.rb |
Overview
An implementation of rspec-mocks’ reference interface. Used when a string is passed to ExampleMethods#object_double, and when a string, named class or named module is passed to ExampleMethods#instance_double, or ExampleMethods#class_double. Represents a reference to the object named (via a constant lookup) by the string.
Class Method Summary
- .new(const_name) ⇒ NamedObjectReference constructor
Instance Attribute Summary
- #defined? ⇒ Boolean readonly
Instance Method Summary
- #const_to_replace ⇒ String (also: #description)
-
#description
Alias for #const_to_replace.
- #target ⇒ Object?
-
#when_loaded {|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.
- #object private
Constructor Details
.new(const_name) ⇒ NamedObjectReference
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 111
def initialize(const_name) @const_name = const_name end
Instance Attribute Details
#defined? ⇒ Boolean
(readonly)
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 116
def defined? !!object end
Instance Method Details
#const_to_replace ⇒ String
Also known as: #description
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 121
def const_to_replace @const_name end
#description
Alias for #const_to_replace.
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 124
alias description const_to_replace
#object (private)
[ GitHub ]# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 143
def object return @object if defined?(@object) @object = Constant.original(@const_name).original_value end
#target ⇒ Object
?
# File 'rspec-mocks/lib/rspec/mocks/object_reference.rb', line 128
def target object end
#when_loaded {|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.