1

我正在使用 Raild 3.2.11、Capybara 2.0.2 和 Factory Girl 4.1.0。

我正在尝试使用 Capybara 在表单中选择多个用户。但是,看起来我的用户没有被创建。视图工作正常,如果我使用 Rails Server,我可以选择多个用户。不知何故,它登录了最后一个创建的实例,Joe_4。

我的测试收到此错误:

Capybara::ElementNotFound:
   Unable to find option "Joe_1"

工厂.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
4

1 回答 1

0

我遇到了同样的问题,解决方案是我运行了 spork。当我停止它时 - 一切正常。在这里阅读更多:

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

于 2013-03-12T14:08:26.210 回答