这里真的很奇怪。当我单独运行我的测试时,我的3个测试中的每一个都通过了。但是,如果我运行上下文,他们每个都会失败,但会间歇性地通过。测试相互碰撞,但我不知道在哪里或如何。以下是错误的测试。
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
也许你会立刻看到一些东西,但我似乎无法找到问题。如果有人有想法为什么会这样,我会喜欢它!谢谢。
要清楚。如果我单独运行其中任何一个,它们都会通过,但如果我运行上下文则会失败。
答案 0 :(得分:1)
您可以使用bisect命令来识别导致测试失败的执行顺序。
命令是:
rspec --bisect
它返回如下内容:
The minimal reproduction command is:
rspec ./spec/features/my_amazing_feature_spec.rb[1:1]
因此,您可以使用它来修复代码并确认修复。