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