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(attributes) ⇒ StripAttributeMatcher
constructor
A new instance of StripAttributeMatcher.
- #matches?(subject) ⇒ Boolean
- #replace_newlines ⇒ Object
- #using(value) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ StripAttributeMatcher
Returns a new instance of StripAttributeMatcher.
25 26 27 28 |
# File 'lib/strip_attributes/matchers.rb', line 25 def initialize(attributes) @attributes = attributes = {} end |
Instance Method Details
#collapse_spaces ⇒ Object
44 45 46 47 |
# File 'lib/strip_attributes/matchers.rb', line 44 def collapse_spaces [:collapse_spaces] = true self end |
#description ⇒ Object
67 68 69 70 |
# File 'lib/strip_attributes/matchers.rb', line 67 def description attrs = @attributes.map { |attr| "##{attr}" }.to_sentence "#{expectation(past: false)} whitespace from #{attrs}" end |
#failure_message ⇒ Object Also known as: failure_message_for_should
RSpec 3.x
55 56 57 |
# File 'lib/strip_attributes/matchers.rb', line 55 def "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
61 62 63 |
# File 'lib/strip_attributes/matchers.rb', line 61 def "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}" end |
#matches?(subject) ⇒ Boolean
30 31 32 33 34 35 36 37 |
# File 'lib/strip_attributes/matchers.rb', line 30 def matches?(subject) @attributes.all? do |attribute| @attribute = attribute subject.send("#{@attribute}=", " #{value} ") subject.valid? subject.send(@attribute) == value and collapse_spaces?(subject) and replace_newlines?(subject) end end |
#replace_newlines ⇒ Object
49 50 51 52 |
# File 'lib/strip_attributes/matchers.rb', line 49 def replace_newlines [:replace_newlines] = true self end |
#using(value) ⇒ Object
39 40 41 42 |
# File 'lib/strip_attributes/matchers.rb', line 39 def using(value) [:value] = value self end |