module Sanitize::Rails::Matchers
Public Instance Methods
sanitize_field(*fields)
click to toggle source
RSpec custom matcher to check for field sanitization
Verifies that the matcher subject sanitizes the given `fields`, by checking that the sanitize callback works as expected.
Matcher can be used in the following variants:
describe Post do # Simplest variant, single field and default values it { should sanitize_field :title } # Multiple fields it { should sanitize_fields :title, :body } # Specifing both text to sanitize and expected result it { should sanitize_field(:title).replacing('©').with('©') } end
# File lib/sanitize/rails/matchers.rb, line 19 def sanitize_field(*fields) if fields.empty? raise ArgumentError, 'need at least one argument' else SanitizeFieldsMatcher.new(*fields) end end
Also aliased as: sanitize_fields