Class: RSpec::Mocks::Constant
- Inherits:
-
Object
- Object
- RSpec::Mocks::Constant
- 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
-
#name ⇒ String
readonly
The fully qualified name of the constant.
-
#original_value ⇒ Object?
The original value (e.g. before it was stubbed by rspec-mocks) of the constant, or nil if the constant was not previously defined.
- #previously_defined ⇒ Object writeonly private
- #stubbed ⇒ Object writeonly private
Class Method Summary collapse
-
.original(name) ⇒ Constant
Queries rspec-mocks to find out information about the named constant.
Instance Method Summary collapse
-
#initialize(name) ⇒ Constant
constructor
private
A new instance of Constant.
-
#previously_defined? ⇒ Boolean
Whether or not the constant was defined before the current example.
-
#stubbed? ⇒ Boolean
Whether or not rspec-mocks has stubbed this constant.
- #to_s ⇒ Object (also: #inspect)
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
#name ⇒ String (readonly)
Returns The fully qualified name of the constant.
31 32 33 |
# File 'lib/rspec/mocks/stub_const.rb', line 31 def name @name end |
#original_value ⇒ Object?
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.
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.
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.
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.
49 50 51 |
# File 'lib/rspec/mocks/stub_const.rb', line 49 def stubbed? @stubbed end |
#to_s ⇒ Object Also known as: inspect
53 54 55 |
# File 'lib/rspec/mocks/stub_const.rb', line 53 def to_s "#<#{self.class.name} #{name}>" end |