Class: RSpec::Mocks::NamedObjectReference

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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.

Instance Method Summary collapse

Constructor Details

#initialize(const_name) ⇒ NamedObjectReference

Returns a new instance of NamedObjectReference.

Parameters:

  • const_name (String)

    constant name



111
112
113
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 111

def initialize(const_name)
  @const_name = const_name
end

Instance Method Details

#const_to_replaceString Also known as: description

Returns the constant name to replace with a double.

Returns:

  • (String)

    the constant name to replace with a double.



121
122
123
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 121

def const_to_replace
  @const_name
end

#defined?Boolean

Returns true if the named constant is defined, false otherwise.

Returns:

  • (Boolean)

    true if the named constant is defined, false otherwise.



116
117
118
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 116

def defined?
  !!object
end

#targetObject?

Returns the target of the verifying double (the named object), or nil if it is not defined.

Returns:

  • (Object, nil)

    the target of the verifying double (the named object), or nil if it is not defined.



128
129
130
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 128

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.

Yields:

  • (Object)

    the target object



137
138
139
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 137

def when_loaded
  yield object if object
end