Class: Expected::Matchers::HaveConstantMatcher
- Inherits:
-
Object
- Object
- Expected::Matchers::HaveConstantMatcher
- Defined in:
- lib/expected/matchers/have_constant.rb
Overview
Class used by #have_constant
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #description ⇒ String
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize(name) ⇒ HaveConstantMatcher
constructor
A new instance of HaveConstantMatcher.
-
#matches?(subject) ⇒ True, False
Run the test.
-
#of_type(type) ⇒ self
Sets the expected type of the constant’s value.
-
#with_value(value) ⇒ self
Sets the expected value of the constant.
Constructor Details
#initialize(name) ⇒ HaveConstantMatcher
Returns a new instance of HaveConstantMatcher.
30 31 32 33 34 35 |
# File 'lib/expected/matchers/have_constant.rb', line 30 def initialize(name) unless name.is_a?(String) || name.is_a?(Symbol) raise 'HaveConstantMatcher constant name must be a String or Symbol' end @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/expected/matchers/have_constant.rb', line 26 def name @name end |
#subject ⇒ Object
Returns the value of attribute subject.
26 27 28 |
# File 'lib/expected/matchers/have_constant.rb', line 26 def subject @subject end |
Instance Method Details
#description ⇒ String
75 76 77 78 79 80 |
# File 'lib/expected/matchers/have_constant.rb', line 75 def description description = "have_constant: #{name}" description += " of_type => #{[:type].inspect}" if .key? :type description += " with_value => #{[:value].inspect}" if .key? :value description end |
#failure_message ⇒ String
65 66 67 |
# File 'lib/expected/matchers/have_constant.rb', line 65 def "Expected #{expectation} (#{@failure})" end |
#failure_message_when_negated ⇒ String
70 71 72 |
# File 'lib/expected/matchers/have_constant.rb', line 70 def "Did not expect #{expectation}" end |
#matches?(subject) ⇒ True, False
Run the test
57 58 59 60 61 62 |
# File 'lib/expected/matchers/have_constant.rb', line 57 def matches?(subject) self.subject = subject constant_exists? && correct_type? && correct_value? end |
#of_type(type) ⇒ self
Sets the expected type of the constant’s value
48 49 50 51 |
# File 'lib/expected/matchers/have_constant.rb', line 48 def of_type(type) [:type] = type self end |
#with_value(value) ⇒ self
Sets the expected value of the constant
40 41 42 43 |
# File 'lib/expected/matchers/have_constant.rb', line 40 def with_value(value) [:value] = value self end |