これは断続的に失敗するテストです:
context "as a regular_user" do
before :each do
@user = FactoryGirl.create(:user, :role => 'regular_user')
visit new_user_session_path unless current_path == new_user_session_path
fill_in "Email", :with => @user.email
fill_in "Password", :with => @user.password
click_button "Sign In"
end
it "removes thing from favorites while on thing index page" do
@things = FactoryGirl.create_list(:thing, 5)
@user.set_mark :favorite, @things.first
@user.reload.favorite_things
visit things_path unless current_path == things_path
expect{
first(:link, "Remove from favorites").click # Sometimes this fails
@user.reload.favorite_things
}.to change { @user.favorite_things.count }.by(-1)
page.should have_content("Sort by")
end
end
私はお気に入り機能を提供するためにマーク可能な宝石を使用しています。
スペックを実行した場合、成功/失敗のパターンはないようですrspec
(一度失敗すると常に失敗するわけではなく、その逆も同様です)。仕様が実行されるguard
(spork
これも使用されている)パターンがある可能性があります。開始guard
してテストに合格すると、そのインスタンスが実行されている間は常に合格しますguard
...同じことが失敗にも当てはまりますguard
。失敗すると、そのインスタンス内の後続のすべての実行guard
も失敗します。
ちょうど今、私はrspec spec/requests/users_spec.rb:148
その1つの仕様を実行するために走りました、そしてそれは失敗しました:
1) Users as a regular_user removes thing from favorites while on thing index page
Failure/Error: click_link "Remove from favorites" # Sometimes this fails
Capybara::ElementNotFound:
Unable to find link "Remove from favorites"
# ./spec/requests/users_spec.rb:155:in `block (4 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:153:in `block (3 levels) in <top (required)>'
rspec spec/requests/users_spec.rb:148
その直後にまた走りましたが、成功しました。
Finished in 0.83754 seconds
1 example, 0 failures
ビューファイルの<% @things.each do |thing| %>
セクションに「asdfasdf」を追加しようとしましたが、それをチェックすると失敗することがあります。ブロックの直前(ビューの同じブロック内に存在する)に追加しようとしましたが、失敗することがあります。ただし、ループ外のテキストを見つけるのに失敗することはありません。index.html.erb
page.should have_content("asdfasdf")
page.should have_selector('.favoritesblock', visible: true)
expect
favoritesblock
@things
<% @things.each do |thing| %>
save_and_open_page
行の直前に追加first(:link, "Remove from favorites").click # Sometimes this fails
し、仕様が失敗したインスタンスを作成することができました。このページには2つのものしか含まれていませんでした(私のFactoryGirl
呼び出しでは5を作成する必要があります)。どちらにも[お気に入りから削除]リンクがありませんでした(お気に入りに追加されたかどうかに応じて、[お気に入りに追加]または[お気に入りから削除]が表示されます。 )。
それに基づいて、仕様の最初の2行を少し変更しようとしましたが、役に立ちませんでした(それでも失敗することがあります)。
5.times { FactoryGirl.create(:thing) }
@user.set_mark :favorite, Thing.first
私が気付いたのは、成功すると、最初に「お気に入りから削除」リンクが表示されますが、5つすべてが表示されるとは限らないということです。
したがって、この仕様が断続的に失敗する理由、または問題の原因を特定するために他に何ができるかを知る必要があります。何か案は?