Class: RSpec::Mocks::Constant
- Inherits:
-
Object
- Object
- RSpec::Mocks::Constant
- Extended by:
- Support::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)
-
- (String) name
readonly
The fully qualified name of the constant.
-
- (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.
Class Method Summary (collapse)
-
+ (Constant) original(name)
Queries rspec-mocks to find out information about the named constant.
Instance Method Summary (collapse)
-
- (Boolean) hidden?
Whether or not rspec-mocks has hidden this constant.
-
- (Constant) initialize(name)
constructor
private
A new instance of Constant.
-
- (Boolean) mutated?
Whether or not rspec-mocks has mutated (stubbed or hidden) this constant.
-
- (Boolean) previously_defined?
Whether or not the constant was defined before the current example.
-
- (Boolean) stubbed?
Whether or not rspec-mocks has stubbed this constant.
-
- (Object) to_s
(also: #inspect)
The default
to_s
isn't very useful, so a custom version is provided.
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
11 12 13 14 15 16 |
# File 'lib/rspec/mocks/mutate_const.rb', line 11 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.
19 20 21 |
# File 'lib/rspec/mocks/mutate_const.rb', line 19 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.
24 25 26 |
# File 'lib/rspec/mocks/mutate_const.rb', line 24 def original_value @original_value end |
Class Method Details
+ (Constant) original(name)
Queries rspec-mocks to find out information about the named constant.
75 76 77 78 |
# File 'lib/rspec/mocks/mutate_const.rb', line 75 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.
49 50 51 |
# File 'lib/rspec/mocks/mutate_const.rb', line 49 def hidden? @hidden end |
- (Boolean) mutated?
Returns Whether or not rspec-mocks has mutated (stubbed or hidden) this constant.
37 38 39 |
# File 'lib/rspec/mocks/mutate_const.rb', line 37 def mutated? @stubbed || @hidden end |
- (Boolean) previously_defined?
Returns Whether or not the constant was defined before the current example.
31 32 33 |
# File 'lib/rspec/mocks/mutate_const.rb', line 31 def previously_defined? @previously_defined end |
- (Boolean) stubbed?
Returns Whether or not rspec-mocks has stubbed this constant.
43 44 45 |
# File 'lib/rspec/mocks/mutate_const.rb', line 43 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.
54 55 56 |
# File 'lib/rspec/mocks/mutate_const.rb', line 54 def to_s "#<#{self.class.name} #{name}>" end |