class StripAttributes::Matchers::StripAttributeMatcher

Public Class Methods

new(attributes) click to toggle source
# File lib/strip_attributes/matchers.rb, line 26
def initialize(attributes)
  @attributes = attributes
  @options = {}
end

Public Instance Methods

collapse_spaces() click to toggle source
# File lib/strip_attributes/matchers.rb, line 40
def collapse_spaces
  @options[:collapse_spaces] = true
  self
end
description() click to toggle source
# File lib/strip_attributes/matchers.rb, line 56
def description
  "#{expectation(false)} whitespace from #{@attributes.map {|el| "##{el}" }.to_sentence}"
end
failure_message() click to toggle source
# File lib/strip_attributes/matchers.rb, line 45
def failure_message # RSpec 3.x
  "Expected whitespace to be #{expectation} from ##{@attribute}, but it was not"
end
Also aliased as: failure_message_for_should
failure_message_for_should()
Alias for: failure_message
failure_message_for_should_not()
failure_message_when_negated() click to toggle source
# File lib/strip_attributes/matchers.rb, line 50
def failure_message_when_negated # RSpec 3.x
  "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}"
end
matches?(subject) click to toggle source
# 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)
  end
end
negative_failure_message()

Private Instance Methods

collapse_spaces?(subject) click to toggle source
# File lib/strip_attributes/matchers.rb, line 62
def collapse_spaces?(subject)
  return true if !@options[:collapse_spaces]

  subject.send("#{@attribute}=", " string    string ")
  subject.valid?
  subject.send(@attribute) == "string string"
end
expectation(past = true) click to toggle source
# File lib/strip_attributes/matchers.rb, line 70
def expectation(past = true)
  expectation = past ? "stripped" : "strip"
  expectation += past ? " and collapsed" : " and collapse" if @options[:collapse_spaces]
  expectation
end