我有以下的正则表达式表达式验证电子邮件VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
意外的正则表达式的行为
我也有以下测试功能
test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post users_path, params: { user: { first_name: "John",
last_name: "Doe",
email: "[email protected]",
password: "foobar123",
password_confirmation: "foobar123" } }
end
follow_redirect!
assert_template 'users/show'
assert is_logged_in?
end
然而,测试失败只有当电子邮件被设置为[email protected]
相同格式的作品每一个其他邮件。我看不出为什么。 此外,当我尝试手动注册后,[email protected]
地址工作完全正常。
Running via Spring preloader in process 5405
Started with run options --seed 28654
FAIL["test_valid_signup_information", UsersSignupTest, 1.127243652001198]
test_valid_signup_information#UsersSignupTest (1.13s)
"User.count" didn't change by 1.
Expected: 2
Actual: 1
test/integration/users_signup_test.rb:19:in `block in <class:UsersSignupTest>'
20/20: [=============================================================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.14680s
感谢,
也许你的测试方法注册用户的地方,该用户已经存在,不提高用户数。 – linden2015
@ linden2015真的不太可能。我怎样才能检查数据库的每一个单一的环境(产品,测试,开发?)谢谢 –
我不认为你的正则表达式是问题:http://rubular.com/r/SC4XTmOwoe –