使用Capybara选择由Factory Girl创建的多个对象



我使用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_testrongpec.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

我有同样的问题,解决方案是我有叉子运行。当我停止时,一切都正常了。阅读更多:

为什么不使用共享ActiveRecord连接的Rspec +硒?

最新更新