Class: RSpec::Mocks::Constant

Inherits:
Object
  • Object
show all
Extended by:
Support::RecursiveConstMethods
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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 Support::RecursiveConstMethods

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

Constructor Details

#initialize(name) {|_self| ... } ⇒ 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.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 11

def initialize(name)
  @name = name
  @previously_defined = false
  @stubbed = false
  @hidden = false
  @valid_name = true
  yield self if block_given?
end

Instance Attribute Details

#hidden=(value) ⇒ Object (writeonly)



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 29

def hidden=(value)
  @hidden = value
end

#nameString (readonly)

Returns The fully qualified name of the constant.

Returns:

  • (String)

    The fully qualified name of the constant.



21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 21

def name
  @name
end

#original_valueObject?

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.



26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 26

def original_value
  @original_value
end

#previously_defined=(value) ⇒ Object (writeonly)



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 29

def previously_defined=(value)
  @previously_defined = value
end

#stubbed=(value) ⇒ Object (writeonly)



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 29

def stubbed=(value)
  @stubbed = value
end

#valid_name=(value) ⇒ Object (writeonly)



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 29

def valid_name=(value)
  @valid_name = 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 containing information about the named constant.



86
87
88
89
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 86

def self.original(name)
  mutator = ::RSpec::Mocks.space.constant_mutator_for(name)
  mutator ? mutator.to_constant : unmutated(name)
end

.unmutated(name) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 68

def self.unmutated(name)
  previously_defined = !!recursive_const_defined?(name)
rescue NameError
  new(name) do |c|
    c.valid_name = false
  end
else
  new(name) do |const|
    const.previously_defined = previously_defined
    const.original_value = recursive_const_get(name) if previously_defined
  end
end

Instance Method Details

#hidden?Boolean

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

Returns:

  • (Boolean)

    Whether or not rspec-mocks has hidden this constant.



51
52
53
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 51

def hidden?
  @hidden
end

#mutated?Boolean

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.



39
40
41
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 39

def mutated?
  @stubbed || @hidden
end

#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.



33
34
35
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 33

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.



45
46
47
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 45

def stubbed?
  @stubbed
end

#to_sObject Also known as: inspect

The default ‘to_s` isn’t very useful, so a custom version is provided.



62
63
64
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 62

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

#valid_name?Boolean

Returns Whether or not the provided constant name is a valid Ruby constant name.

Returns:

  • (Boolean)

    Whether or not the provided constant name is a valid Ruby constant name.



57
58
59
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 57

def valid_name?
  @valid_name
end