jeudi 6 juin 2019

Checking regex in rails TestCase

So in Rails I've written these validations for an email :

validates :email, presence: true, uniqueness: true
validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/

When I try to submit something with a wrong email this works because it sends me an error, but when I try to test it like this :

test "should not save if email is not valid" do
    slogan = Slogan.create(firstname: 'tristan', lastname: 'vermeesch', email: 'titivermeeschgmail.com', slogan: 'Test')
    assert slogan.valid?, "Tried to save with an email that is not valid"
  end

The test fails, can someone please help?

Aucun commentaire:

Enregistrer un commentaire