English 中文(简体)
rspec 电子邮件验证
原标题:rspec email validation

我在学习 Rspec 。 当我运行电子邮件验证的测试框时, 我得到一个无法理解的错误。 请解释 。

  1) User should check for email validation
     Failure/Error: @test_user.should have(1).errors_on(:email)
       expected 1 errors on :email, got 2
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)> 

Finished in 0.12903 seconds
2 examples, 1 failure

我的测试案例如下:

  it"should check whether name is present or not" do
    @test_user.name = nil
    @test_user.should have(1).errors_on(:name)
  end

  it "should check for email validation"do
    @test_user.email = nil
    @test_user.should have(2).errors_on(:email)
  end
end
最佳回答

如果您同时使用存在验证器和某种格式验证器来重新验证电子邮件属性,那么通过将属性设定为零就会有两个错误。

也许尝试一些东西,比如:

validates :email, presence: true, 
                  format: { with: %rA([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})/,
                            allow_nil: true  }
问题回答

暂无回答




相关问题
Emailed key validation for user registration

I have a web app. I do not wish to maintain login information so I employ the gradually getting popular method of logging in thro openid, google, yahoo, etc. The user chooses which avenue of login (...

joomla login email verification is not working!

i have installed joomla 1.5 on a apache server with mysql in my windows server.the problem is when somebody try to register there is no email sent for the verification. how can i setup that ? how can ...

How to verify email sender address is not spoofed? [closed]

As per this question I asked previously on Google App Engine, if I have access to all the information in a standard email, not just the From, To, Subject, Body fields, but also all the headers and ...

How should I validate an e-mail address?

What s a good technique for validating an e-mail address (e.g. from a user input field) in Android? org.apache.commons.validator.routines.EmailValidator doesn t seem to be available. Are there any ...

check if email are valid and exists

I am working on a web app that requires me to check if the users email are valid and exists. (I do the regex check) The question is what is best practice of verifying that an email exists? Here are ...

How to weed out bad emails (in php)?

I have a site where users register for an account. I have an internal communication system, that sends them an email when they get a private message. I dont force people to confirm their email, so ...

Check if a string is an email address in PHP

I am trying to do an SQL query, but I need to check somehow if the value is an email address. I need a way to check if $user is an email address, because I have user values such as this in my table. ...

热门标签