【发布时间】:2015-07-04 19:12:19
【问题描述】:
我是 ruby on rails 的初学者。我正在尝试使用 rspec 和 capybara gems 测试重复的电子邮件场景。
这是我的用户测试规范:
require 'rails_helper'
feature "User signs up", type: :feature do
# before do
# click_link "Sign up"
# expect(current_path).to eq(new_user_registration_path)
# fill_in "Name", with: "Test"
# fill_in "Surname", with: "Test"
# fill_in "Email", with: "tester@example.tld"
# fill_in "Password", with: "test-password"
# fill_in "Password confirmation", with: "test-password"
# click_button "Sign up"
# end
scenario "successfully" do
visit "/"
click_link "Sign up"
expect(current_path).to eq(new_user_registration_path)
fill_in "Name", with: "Test"
fill_in "Surname", with: "Test"
fill_in "Email", with: "tester@example.tld"
fill_in "Password", with: "test-password"
fill_in "Password confirmation", with: "test-password"
click_button "Sign up"
expect(current_path).to eq "/"
expect(page).to have_content(
"A message with a confirmation link has been sent to your email address.
Please follow the link to activate your account."
)
open_email "tester@example.tld", with_subject: "Confirmation instructions"
visit_in_email "Confirm my account"
expect(current_path).to eq new_user_session_path
expect(page).to have_content "Your email address has been successfully confirmed."
fill_in "Email", with: "tester@example.tld"
fill_in "Password", with: "test-password"
click_button "Log in"
expect(current_path).to eq "/"
expect(page).to have_content "Signed in successfully."
expect(page).to have_content "Hello Test"
end
scenario "usuccessfully - Invalid email " do
visit "/"
click_link "Sign up"
expect(current_path).to eq(new_user_registration_path)
fill_in "Name", with: "Test"
fill_in "Surname", with: "Test"
fill_in "Email", with: "invalid-email"
fill_in "Password", with: "test-password"
fill_in "Password confirmation", with: "test-password"
click_button "Sign up"
expect(current_path).to eq "/users"
expect(page).to have_content(
"Email is invalid"
)
end
scenario "usuccessfully - Duplicate email " do
visit "/"
click_link "Sign up"
expect(current_path).to eq(new_user_registration_path)
fill_in "Name", with: "Test"
fill_in "Surname", with: "Test"
fill_in "Email", with: "tester@example.tld"
fill_in "Password", with: "test-password"
fill_in "Password confirmation", with: "test-password"
click_button "Sign up"
expect(current_path).to eq "/users"
expect(page).to have_content(
"Email has already been taken"
)
end
end
feature "User signing", type: :feature do
scenario "usuccessfully" do
visit "/"
click_link "Sign in"
expect(current_path).to eq(new_user_session_path)
fill_in "Email", with: "wrong-email@example.tld"
fill_in "Password", with: "wrong-password"
click_button "Log in"
expect(current_path).to eq(new_user_session_path)
expect(page).to have_content(
"Invalid email or password."
)
# expect(current_path).to eq new_user_session_path
# expect(page).to have_content "Your email address has been successfully confirmed."
# fill_in "Email", with: "tester@example.tld"
# fill_in "Password", with: "test-password"
# click_button "Log in"
# expect(current_path).to eq "/"
# expect(page).to have_content "Signed in successfully."
# expect(page).to have_content "Hello Zein"
end
end
我收到以下故障:
1) User signs up usuccessfully - Duplicate email
Failure/Error: expect(current_path).to eq "/users"
expected: "/users"
got: "/"
(compared using ==)
# ./spec/features/user_sign_ups_spec.rb:77:in `block (2 levels) in <top (required)>'
如何使用 capybara gem 创建重复用户? 感谢您的帮助:)
【问题讨论】:
标签: ruby-on-rails ruby rspec capybara