Class: StripAttributes::Matchers::StripAttributeMatcher
- Inherits:
-
Object
- Object
- StripAttributes::Matchers::StripAttributeMatcher
- Defined in:
- lib/strip_attributes/matchers.rb
Instance Method Summary collapse
- #collapse_spaces ⇒ Object
- #description ⇒ Object
-
#failure_message ⇒ Object
(also: #failure_message_for_should)
RSpec 3.x.
-
#failure_message_when_negated ⇒ Object
(also: #failure_message_for_should_not, #negative_failure_message)
RSpec 3.x.
-
#initialize(attribute) ⇒ StripAttributeMatcher
constructor
A new instance of StripAttributeMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ StripAttributeMatcher
Returns a new instance of StripAttributeMatcher.
20 21 22 23 |
# File 'lib/strip_attributes/matchers.rb', line 20 def initialize(attribute) @attribute = attribute @options = {} end |
Instance Method Details
#collapse_spaces ⇒ Object
31 32 33 34 |
# File 'lib/strip_attributes/matchers.rb', line 31 def collapse_spaces @options[:collapse_spaces] = true self end |
#description ⇒ Object
47 48 49 |
# File 'lib/strip_attributes/matchers.rb', line 47 def description "#{expectation(false)} whitespace from ##{@attribute}" end |
#failure_message ⇒ Object Also known as: failure_message_for_should
RSpec 3.x
36 37 38 |
# File 'lib/strip_attributes/matchers.rb', line 36 def # RSpec 3.x "Expected whitespace to be #{expectation} from ##{@attribute}, but it was not" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not, negative_failure_message
RSpec 3.x
41 42 43 |
# File 'lib/strip_attributes/matchers.rb', line 41 def # RSpec 3.x "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}" end |
#matches?(subject) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/strip_attributes/matchers.rb', line 25 def matches?(subject) subject.send("#{@attribute}=", " string ") subject.valid? subject.send(@attribute) == "string" and collapse_spaces?(subject) end |