简体   繁体   中英

Unable to run more than one spec scenario

I got problem with my Capybara spec. The thing is when I run spec with more than one scenario it crashes - commenting any of this two scenarios makes test passing. Error says that there cannot be created another record with the same ID in database (I have to create this object, as test seed data, with the specifically set ID). However, this object is created one time in the background clause at the beginning of the spec. Does anybody have idea, why this error shows up? What is more, there could be nothing in the second scenario (or vice versa) and test will not pass. Just won't pass the second scenario on the run.

Structure of the spec:

feature "..." do
  given(...){...}

  background do
    ...
    FactoryGirl.create(:my_object, id: 17)
    ...
    ...logging into system
  end

  scenario "first" do
    ...
  end


  scenario "second" do
    ...
  end

end

Convert

 background do
    ...
    FactoryGirl.create(:my_object, id: 17)
    ...
    ...logging into system
  end

To--------------

before(:all) do
    ...
    FactoryGirl.create(:my_object, id: 17)
    ...
    ...logging into system
  end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM