Module: Sanitize::Rails::Matchers

Defined in:
lib/sanitize/rails/matchers.rb

Defined Under Namespace

Modules: RSpec2, RSpec3 Classes: SanitizeFieldsMatcher

Instance Method Summary collapse

Instance Method Details

#sanitize_field(*fields) ⇒ Object Also known as: sanitize_fields

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


19
20
21
22
23
24
25
# 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