Class: StripAttributes::Matchers::StripAttributeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/strip_attributes/matchers.rb

Instance Method Summary collapse

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_spacesObject



40
41
42
43
# File 'lib/strip_attributes/matchers.rb', line 40

def collapse_spaces
  @options[:collapse_spaces] = true
  self
end

#descriptionObject



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_messageObject Also known as: failure_message_for_should

RSpec 3.x



50
51
52
# File 'lib/strip_attributes/matchers.rb', line 50

def failure_message # RSpec 3.x
  "Expected whitespace to be #{expectation} from ##{@attribute}, but it was not"
end

#failure_message_when_negatedObject 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 failure_message_when_negated # RSpec 3.x
  "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (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_newlinesObject



45
46
47
48
# File 'lib/strip_attributes/matchers.rb', line 45

def replace_newlines
  @options[:replace_newlines] = true
  self
end