Class: StripTags::Matchers::StripTagsMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/strip-tags/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ StripTagsMatcher

Returns a new instance of StripTagsMatcher.



23
24
25
26
# File 'lib/strip-tags/matchers.rb', line 23

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

Instance Method Details

#descriptionObject



52
53
54
# File 'lib/strip-tags/matchers.rb', line 52

def description
  "#{expectation(false)} tags from #{@attributes.map {|el| "##{el}" }.to_sentence}"
end

#failure_messageObject Also known as: failure_message_for_should

RSpec 3.x



41
42
43
# File 'lib/strip-tags/matchers.rb', line 41

def failure_message # RSpec 3.x
  "Expected tags 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



46
47
48
# File 'lib/strip-tags/matchers.rb', line 46

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/strip-tags/matchers.rb', line 28

def matches?(subject)
  @attributes.all? do |attribute|
    @attribute = attribute
    subject.send("#{@attribute}=", "foo> & <<script>alert('xss')</script>")
    subject.valid?
    if Gem::Version.new(Rails.version) >= Gem::Version.new("7.1")
      subject.send(@attribute) == "foo> & <alert('xss')"
    else
      subject.send(@attribute) == "foo> & <"
    end
  end
end