Class: RSpec::Mocks::ObjectReference

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/object_reference.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) for(object_module_or_name, allow_direct_object_refs = false)

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



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec/mocks/object_reference.rb', line 8

def self.for(object_module_or_name, allow_direct_object_refs = false)
  case object_module_or_name
    when Module then DirectModuleReference.new(object_module_or_name)
    when String then 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