Class: RSpec::Mocks::ObjectReference

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

Constant Summary collapse

MODULE_NAME_METHOD =
Module.instance_method(:name)

Class Method Summary collapse

Class Method Details

.for(object_module_or_name, allow_direct_object_refs = false) ⇒ Object

Returns an appropriate Object or Module reference based on the given argument.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/object_reference.rb', line 7

def self.for(object_module_or_name, allow_direct_object_refs=false)
  case object_module_or_name
  when Module
    if anonymous_module?(object_module_or_name)
      DirectObjectReference.new(object_module_or_name)
    else
      # Use a `NamedObjectReference` if it has a name because this
      # will use the original value of the constant in case it has
      # been stubbed.
      NamedObjectReference.new(name_of(object_module_or_name))
    end
  when String
    NamedObjectReference.new(object_module_or_name)
  else
    if allow_direct_object_refs
      DirectObjectReference.new(object_module_or_name)
    else
      raise ArgumentError,
            "Module or String expected, got #{object_module_or_name.inspect}"
    end
  end
end