2016-11-06 7 views
1

ここでは本当に奇妙な問題です。孤立してテストを実行すると、それぞれの3つのテストが合格します。文脈を動かすと、それぞれ失敗しますが断続的に合格します。テストはお互いに実行されていますが、私はどこでどのように動作するのか分かりません。ここに欠陥のあるテストがあります。テストは分離していますが、実行中に失敗する - RSpec

context "creating an account" do 
    let!(:user) { login_user } 
    let!(:plan) { create(:plan, :public, :unlimited, name: "Private Eye") } 

    before do 
     allow_any_instance_of(Gabba::Gabba).to receive_messages(event: true) 
    end 

    it "can create a new account" do 
     visit new_account_path 

     fill_in :account_name, with: "New Account" 

     find("#stripe_card_token").set("tok_3HUgs79WEx47q9") 

     VCR.use_cassette("stripe/create_customer_paid_plan") do 
     choose("plan_id_2") 
     fill_in :card_number, with: "4242424242424242" 
     select "12", from: :date_month 
     select Date.current.year, from: :date_year 

     expect { click_button "Complete Project Setup" } 
      .to change(Account, :count).by(1) 
      .and change(user.reload.accounts, :count).by(1) 
     end 

     account = Account.find_by(name: "New Account") 

     expect(current_path).to eq(snitches_path) 
     expect(account.name).to eq("New Account") 
     expect(account.cc_last4).to eq("4242") 
     expect(account.cc_expiration_year).to eq(2016) 
     expect(account.cc_expiration_month).to eq(12) 
    end 

    it "for a paid plan without a credit card" do 
     visit new_account_path 

     choose("plan_id_2") 
     fill_in :account_name, with: "My New Account" 

     expect { click_button "Complete Project Setup" } 
     .not_to change(Account, :count) 

     expect(page).to have_content("Oops. You need to enter a credit card to sign up for a paid plan.") 
    end 

    it "switches user to the new account upon creation" do 
     visit new_account_path 

     find("#stripe_card_token").set("tok_3HUgs79WEx47q9") 

     VCR.use_cassette("stripe/create_customer_paid_plan") do 
     choose("plan_id_2") 
     fill_in :account_name, with: "My New Account" 
     fill_in :card_number, with: "4242424242424242" 
     select "12", from: :date_month 
     select Date.current.year, from: :date_year 

     click_button "Complete Project Setup" 
     end 

     expect(current_path).to eq(snitches_path) 
     expect(page).to have_content("My New Account") 
     expect(Account.find_by(id: current_account).name).to eq("My New Account") 
    end 
    end 

多分あなたはバットからすぐに何かが見えますが、私は問題を見つけることができません。誰かがなぜこのようなことが起こるのかというアイデアがあるなら、私はそれを愛するでしょう!ありがとうございました。

これらを単独で実行すると、それぞれが成功しますが、コンテキストを実行すると失敗します。

答えて

1

bisectコマンドを使用すると、テストが失敗する実行順序を特定できます。

コマンドは次のとおりです。

rspec --bisect 

それはこのような何かを返す:

The minimal reproduction command is: 
    rspec ./spec/features/my_amazing_feature_spec.rb[1:1] 

だから、あなたのコードを修正して、修正を確認するためにそれを使用することができます。

関連する問題