Class: StripTags::Matchers::StripTagsMatcher
- Inherits:
-
Object
- Object
- StripTags::Matchers::StripTagsMatcher
- Defined in:
- lib/strip-tags/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
-
#failure_message ⇒ Object
(also: #failure_message_for_should)
RSpec 3.x.
-
#failure_message_when_negated ⇒ Object
(also: #failure_message_for_should_not, #negative_failure_message)
RSpec 3.x.
-
#initialize(attributes) ⇒ StripTagsMatcher
constructor
A new instance of StripTagsMatcher.
- #matches?(subject) ⇒ Boolean
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
#description ⇒ Object
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_message ⇒ Object Also known as: failure_message_for_should
RSpec 3.x
41 42 43 |
# File 'lib/strip-tags/matchers.rb', line 41 def # RSpec 3.x "Expected tags to be #{expectation} from ##{@attribute}, but it was not" end |
#failure_message_when_negated ⇒ Object 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 # RSpec 3.x "Expected tags to remain on ##{@attribute}, but it was #{expectation}" end |
#matches?(subject) ⇒ 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 |