Class: RSpec::Mocks::Constant

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

Overview

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Constant) initialize(name)

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

85
86
87
88
89
90
# File 'lib/rspec/mocks/mutate_const.rb', line 85
def initialize(name)
  @name = name
  @previously_defined = false
  @stubbed = false
  @hidden = false
end

Instance Attribute Details

- (String) name (readonly)

Returns The fully qualified name of the constant.

Returns:

  • (String)

    The fully qualified name of the constant.

93
94
95
# File 'lib/rspec/mocks/mutate_const.rb', line 93
def name
  @name
end

- (Object?) original_value

Returns The original value (e.g. before it was mutated 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 mutated by rspec-mocks) of the constant, or nil if the constant was not previously defined.

98
99
100
# File 'lib/rspec/mocks/mutate_const.rb', line 98
def original_value
  @original_value
end

Class Method Details

+ (Constant) original(name)

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.

149
150
151
152
# File 'lib/rspec/mocks/mutate_const.rb', line 149
def self.original(name)
  mutator = ::RSpec::Mocks.space.constant_mutator_for(name)
  mutator ? mutator.to_constant : unmutated(name)
end

Instance Method Details

- (Boolean) hidden?

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

Returns:

  • (Boolean)

    Whether or not rspec-mocks has hidden this constant.

123
124
125
# File 'lib/rspec/mocks/mutate_const.rb', line 123
def hidden?
  @hidden
end

- (Boolean) mutated?

Returns Whether or not rspec-mocks has mutated (stubbed or hidden) this constant.

Returns:

  • (Boolean)

    Whether or not rspec-mocks has mutated (stubbed or hidden) this constant.

111
112
113
# File 'lib/rspec/mocks/mutate_const.rb', line 111
def mutated?
  @stubbed || @hidden
end

- (Boolean) previously_defined?

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.

105
106
107
# File 'lib/rspec/mocks/mutate_const.rb', line 105
def previously_defined?
  @previously_defined
end

- (Boolean) stubbed?

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

Returns:

  • (Boolean)

    Whether or not rspec-mocks has stubbed this constant.

117
118
119
# File 'lib/rspec/mocks/mutate_const.rb', line 117
def stubbed?
  @stubbed
end

- (Object) to_s Also known as: inspect

The default to_s isn't very useful, so a custom version is provided.

128
129
130
# File 'lib/rspec/mocks/mutate_const.rb', line 128
def to_s
  "#<#{self.class.name} #{name}>"
end