Tôi đang sử dụng minitest với cô gái nhà máy và capybara để kiểm tra tích hợp. Capybara hoạt động tốt khi tôi không sử dụng máy cô gái để tạo ra một đối tượng người dùng, như thế này:Capybara không hoạt động với nhà máy nữ
it "logs in a user successfully" do
visit signup_path
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "rockawaybeach"
fill_in "Password confirmation", :with => "rockawaybeach"
click_button "Create User"
current_path == "/"
page.text.must_include "Signed up!"
visit login_path
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "rockawaybeach"
check "Remember me"
click_button "Log in"
current_path == "/dashboard"
page.text.must_include "Logged in!"
page.text.must_include "Your Dashboard"
end
Nhưng ngay sau khi tôi cố gắng tạo ra một người dùng với máy cô gái những điều kỳ lạ bắt đầu xảy ra, chẳng hạn như các phương pháp truy cập và các phương thức click_button ngừng hoạt động. Ví dụ, có dường như không có bất cứ điều gì sai trái với thử nghiệm này:
require "test_helper"
describe "Password resets" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "emails user when requesting password reset" do
visit login_path
click_link "password"
fill_in "Email", :with => user.email
click_button "Reset my password"
end
end
Và đây là factories.rb tôi:
FactoryGirl.define do
factory :user do |f|
f.sequence(:email) { |n| "foo#{n}@example.com" }
f.password "secret"
f.password_confirmation "secret"
end
end
Đây là lỗi thực tế mà tôi nhận được:
est_0001_emails user when requesting password reset 0:00:01.624 ERROR
undefined local variable or method `login_path' for #<#<Class:0x007fc2db48d820>:0x007fc2df337e40>
Nhưng, visit login_path
hoạt động tốt nếu tôi loại bỏ @user = FactoryGirl.create(:user)
là thứ là một lỗi với Capybara? Hay tôi đang làm gì sai ở đây?
điều gì sẽ xảy ra nếu bạn thay thế khối trước đó trong thử nghiệm của bạn bằng let (: user) {Factory (: user)}? – shicholas
Điều đó có cùng lỗi. Có vẻ như Capybara chỉ không gửi biểu mẫu. –
Dòng này có phải là sự cố không? 'fill_in" Email ",: with => user.email' Không phải là' @ user.email'? –