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.



25
26
27
28
# File 'lib/strip_attributes/matchers.rb', line 25

def initialize(attributes)
  @attributes = attributes
  @options = {}
end

Instance Method Details

#collapse_spacesObject



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

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

#descriptionObject



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

RSpec 3.x



55
56
57
# File 'lib/strip_attributes/matchers.rb', line 55

def failure_message
  "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



61
62
63
# File 'lib/strip_attributes/matchers.rb', line 61

def failure_message_when_negated
  "Expected whitespace to remain on ##{@attribute}, but it was #{expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

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



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

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

#using(value) ⇒ Object



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

def using(value)
  @options[:value] = value
  self
end