Class: StripAttributes::Matchers::StripAttributeMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ StripAttributeMatcher

Returns a new instance of StripAttributeMatcher.



20
21
22
23
# File 'lib/strip_attributes/matchers.rb', line 20

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

Instance Method Details

#collapse_spacesObject



31
32
33
34
# File 'lib/strip_attributes/matchers.rb', line 31

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

#descriptionObject



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

def description
  "#{expectation(false)} whitespace from ##{@attribute}"
end

#failure_messageObject Also known as: failure_message_for_should

RSpec 3.x



36
37
38
# File 'lib/strip_attributes/matchers.rb', line 36

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



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

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  subject.send("#{@attribute}=", " string ")
  subject.valid?
  subject.send(@attribute) == "string" and collapse_spaces?(subject)
end