Class: RSpec::Mocks::Constant

Inherits:
Object
  • Object
show all
Extended by:
RecursiveConstMethods
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)

Methods included from RecursiveConstMethods

const_defined_on?, constants_defined_on, get_const_defined_on, normalize_const_name, recursive_const_defined?, recursive_const_get

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.

A new instance of Constant

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

Instance Attribute Details

- (Object) hidden=(value) (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.

100
101
102
# File 'lib/rspec/mocks/mutate_const.rb', line 100
def hidden=(value)
  @hidden = value
end

- (String) name (readonly)

The fully qualified name of the constant.

Returns:

  • (String)

    The fully qualified name of the constant.

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

- (Object?) original_value

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.

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

- (Object) previously_defined=(value) (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.

100
101
102
# File 'lib/rspec/mocks/mutate_const.rb', line 100
def previously_defined=(value)
  @previously_defined = value
end

- (Object) stubbed=(value) (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.

100
101
102
# File 'lib/rspec/mocks/mutate_const.rb', line 100
def stubbed=(value)
  @stubbed = 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.

148
149
150
151
# File 'lib/rspec/mocks/mutate_const.rb', line 148
def self.original(name)
  mutator = ConstantMutator.find(name)
  mutator ? mutator.to_constant : unmutated(name)
end

+ (Object) unmutated(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.

132
133
134
135
136
137
138
139
140
# File 'lib/rspec/mocks/mutate_const.rb', line 132
def self.unmutated(name)
  const = new(name)
  const.previously_defined = recursive_const_defined?(name)
  const.stubbed = false
  const.hidden = false
  const.original_value = recursive_const_get(name) if const.previously_defined?
  const
end

Instance Method Details

- (Boolean) hidden?

Whether or not rspec-mocks has hidden this constant.

Returns:

  • (Boolean)

    Whether or not rspec-mocks has hidden this constant.

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

- (Boolean) mutated?

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.

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

- (Boolean) previously_defined?

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

Returns:

  • (Boolean)

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

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

- (Boolean) stubbed?

Whether or not rspec-mocks has stubbed this constant.

Returns:

  • (Boolean)

    Whether or not rspec-mocks has stubbed this constant.

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

- (Object) to_s Also known as: inspect

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