Read more

Testing validates_format_of with Shoulda matchers

Henning Koch
September 02, 2010Software engineer at makandra GmbH

Don't use should validate_format_of(...) because that matcher works in weird ways. Use the allow_value matcher instead:

describe Email, '#sender' do
  # > Rspec 3 should syntax
  it { should allow_value("email@addresse.foo").for(:sender) }
  it { should_not allow_value("foo").for(:sender) }
  
  # Rspec 3 expect syntax
  it { is_expected.to allow_value("email@addresse.foo").for(:sender) }
  it { is_expected.not_to allow_value("foo").for(:sender) }
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Errors that may occur if you do use should validate_format_of(...):

NoMethodError: private method `gsub' called for /\A[a-z0-9\-_]+\z/:Regexp
Posted by Henning Koch to makandra dev (2010-09-02 14:42)