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
也許你會看到蝙蝠的東西,但我似乎無法找到問題。如果有人有想法,爲什麼會發生這種情況,我會喜歡它!謝謝。
只是要清楚。如果我孤立地運行其中的任何一個,如果我運行上下文,它們每個都會通過但失敗。