Class: AttributeNormalizer::RSpecMatcher::NormalizeAttribute
- Inherits:
-
Object
- Object
- AttributeNormalizer::RSpecMatcher::NormalizeAttribute
- Defined in:
- lib/attribute_normalizer/rspec_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object (also: #negative_failure_message)
- #from(value) ⇒ Object
-
#initialize(attribute) ⇒ NormalizeAttribute
constructor
A new instance of NormalizeAttribute.
- #matches?(subject) ⇒ Boolean
- #to(value) ⇒ Object
Constructor Details
#initialize(attribute) ⇒ NormalizeAttribute
Returns a new instance of NormalizeAttribute.
11 12 13 14 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 11 def initialize(attribute) @attribute = attribute @from = '' end |
Instance Method Details
#description ⇒ Object
16 17 18 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 16 def description "normalize #{@attribute} from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}" end |
#failure_message ⇒ Object
20 21 22 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 20 def "#{@attribute} did not normalize as expected! \"#{@subject.send(@attribute)}\" != #{@to.nil? ? 'nil' : "\"#{@to}\""}" end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
24 25 26 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 24 def "expected #{@attribute} to not be normalized from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}" end |
#from(value) ⇒ Object
29 30 31 32 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 29 def from(value) @from = value self end |
#matches?(subject) ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 39 def matches?(subject) @subject = subject @subject.send("#{@attribute}=", @from) @subject.send(@attribute) == @to end |
#to(value) ⇒ Object
34 35 36 37 |
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 34 def to(value) @to = value self end |