开发者

How to test email validation with cucumber

开发者 https://www.devze.com 2023-01-15 16:51 出处:网络
I\'m wondering how to write a cucumber feature and spec to check the following validation Field email, here is the validation in the model

I'm wondering how to write a cucumber feature and spec to check the following validation

Field email, here is the validation in the model

validates :email, :presence => true, 
                  :length => {:minimum => 3, :maximum =开发者_如何学Python> 254},
                  :uniqueness => true,
                  :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}

Thanks


Here's my opinion on what you're doing, take it or leave it.

1) You should be using Test::Unit or Rspec to test model behavior such as validations. Other tools like Shoulda can also provide additional confidence.

2) Use the validation helper methods such as validates_presence_of :email (http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html). It will make your code easier to read and more in line with standard rails convention.

3) Don't reinvent the wheel. Tools like authlogic already take care of email validation. Even if you're not validating a user sign up, you can still use their email regex like:

validates_format_of :email, :with => Authlogic::Regex.email
0

精彩评论

暂无评论...
验证码 换一张
取 消