Class: RSpec::Mocks::Constant

Inherits:
Object
  • Object
show all
Extended by:
RecursiveConstMethods
Defined in:
lib/rspec/mocks/stub_const.rb

Overview

Provides information about constants that may (or may not) have been stubbed by rspec-mocks.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RecursiveConstMethods

recursive_const_defined?, recursive_const_get

Constructor Details

#initialize(name) ⇒ Constant

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Constant.



26
27
28
# File 'lib/rspec/mocks/stub_const.rb', line 26

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns The fully qualified name of the constant.

Returns:

  • (String)

    The fully qualified name of the constant.



31
32
33
# File 'lib/rspec/mocks/stub_const.rb', line 31

def name
  @name
end

#original_valueObject?

Returns The original value (e.g. before it was stubbed by rspec-mocks) of the constant, or nil if the constant was not previously defined.

Returns:

  • (Object, nil)

    The original value (e.g. before it was stubbed by rspec-mocks) of the constant, or nil if the constant was not previously defined.



36
37
38
# File 'lib/rspec/mocks/stub_const.rb', line 36

def original_value
  @original_value
end

#previously_defined=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/rspec/mocks/stub_const.rb', line 39

def previously_defined=(value)
  @previously_defined = value
end

#stubbed=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/rspec/mocks/stub_const.rb', line 39

def stubbed=(value)
  @stubbed = value
end

Class Method Details

.original(name) ⇒ Constant

Queries rspec-mocks to find out information about the named constant.

Parameters:

  • name (String)

    the name of the constant

Returns:

  • (Constant)

    an object contaning information about the named constant.



74
75
76
77
# File 'lib/rspec/mocks/stub_const.rb', line 74

def self.original(name)
  stubber = ConstantStubber.find(name)
  stubber ? stubber.to_constant : unstubbed(name)
end

Instance Method Details

#previously_defined?Boolean

Returns Whether or not the constant was defined before the current example.

Returns:

  • (Boolean)

    Whether or not the constant was defined before the current example.



43
44
45
# File 'lib/rspec/mocks/stub_const.rb', line 43

def previously_defined?
  @previously_defined
end

#stubbed?Boolean

Returns Whether or not rspec-mocks has stubbed this constant.

Returns:

  • (Boolean)

    Whether or not rspec-mocks has stubbed this constant.



49
50
51
# File 'lib/rspec/mocks/stub_const.rb', line 49

def stubbed?
  @stubbed
end

#to_sObject Also known as: inspect



53
54
55
# File 'lib/rspec/mocks/stub_const.rb', line 53

def to_s
  "#<#{self.class.name} #{name}>"
end