Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 测试隔离通过,但在运行suite-RSpec时失败_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails 测试隔离通过,但在运行suite-RSpec时失败

Ruby on rails 测试隔离通过,但在运行suite-RSpec时失败,ruby-on-rails,rspec,Ruby On Rails,Rspec,这真是个奇怪的问题。当我单独运行测试时,我的3个测试中的每一个都通过了。但是,如果我运行上下文,它们都会失败,但会断断续续地通过。考试互相碰头,但我不知道在哪里或如何进行。这是错误的测试 context "creating an account" do let!(:user) { login_user } let!(:plan) { create(:plan, :public, :unlimited, name: "Private Eye") } before

这真是个奇怪的问题。当我单独运行测试时,我的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 
也许你会马上看到一些东西,但我似乎找不到问题所在。如果有人知道为什么会发生这种事,我会喜欢的!多谢各位


我只是想说清楚。如果我单独运行其中任何一个,它们都会通过,但如果我运行上下文,它们就会失败

您可以使用bisect命令来识别导致测试失败的执行顺序

命令是:

rspec --bisect
它返回如下内容:

The minimal reproduction command is:
  rspec ./spec/features/my_amazing_feature_spec.rb[1:1]
因此,您可以使用它来修复代码并确认修复