我正在使用Raild 3.2.11,Capybara 2.0.2和Factory Girl 4.1.0。
我正在尝试使用Capybara选择表单中的多个用户。但是看起来我的用户没有被创建。视图工作正常,如果我使用Rails服务器,我可以选择多个用户。不知何故,它登录了最后创建的实例Joe_4。
我的测试收到此错误:
Capybara::ElementNotFound:
Unable to find option "Joe_1"
Factories.rb
FactoryGirl.define do
sequence :nickname do |n|
"Joe_#{n}"
end
sequence :email do |e|
"joe_#{e}@kebas.com"
end
factory :player, :aliases =>
[:first_pair_1st_player, :first_pair_2nd_player,
:second_pair_1st_player, :second_pair_2nd_player] do
nickname
email
password "password"
password_confirmation "password"
end
end
功能/ match_test_spec.rb
require 'spec_helper'
describe "Entered matched results" do
before :each do
4.times do
FactoryGirl.create(:player)
end
end
context "should fail when," do
it "the score are the same" do
visit root_path
valid_player_login
click_link "New Match"
select('Joe_1', :from => 'doubles_match_first_pair_1st_player_id')
select('Joe_2', :from => 'doubles_match_first_pair_2nd_player_id')
select('Joe_3', :from => 'doubles_match_second_pair_1st_player_id')
select('Joe_4', :from => 'doubles_match_second_pair_1st_player_id')
fill_in "doubles_match_first_pair_score", :with => "14"
fill_in "doubles_match_second_pair_score", :with => "14"
click_link_or_button "Game Over"
page.should have_content("Match can't end with the same score")
end
end
答案 0 :(得分:0)
我有同样的问题,解决方案是我有spork运行。当我停止它 - 一切正常。在这里阅读更多内容:
Why not use shared ActiveRecord connections for Rspec + Selenium?