Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are these Rspec examples not occuring within a DB transaction?
    primarykey
    data
    text
    <p>I'm writing a typical test in my application where I create a model through a form and check that the model count equals 1.</p> <p>The test fails because there are already multiple records in the test DB, and this count increases each time I run my tests. It looks like each example isn't happening inside a transaction (being rolled back) like it's supposed to, and I don't know why.</p> <p>I have this line in my spec_helper.rb file, which is supposed to run each example in a transaction:</p> <pre><code>config.use_transactional_fixtures = true </code></pre> <p>Here is my spec that keeps generating model objects:</p> <pre><code>require 'spec_helper' describe "Admin artwork pages" do subject { page } let(:gallery) { FactoryGirl.create(:gallery) } describe "artwork creation" do context "with valid attributes" do it "creates new artwork" do visit admin_gallery_artworks_path(gallery_id: gallery.id) click_link 'Add new artwork' fill_in 'artwork_title', with: 'Still Life' click_button 'Create Artwork' page.should have_text 'Successfully created' Artwork.count.should eq 1 end end end end </code></pre> <p>Here's the error message from Rspec:</p> <pre><code>Failures: 1) Admin artwork pages artwork creation with valid attributes creates new artwork Failure/Error: Artwork.count.should eq 1 expected: 1 got: 153 (compared using ==) </code></pre> <p>Edit: Contents of my spec_helper.rb file:</p> <pre><code>ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rails' require 'capybara/rspec' Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = "random" # Include route helpers config.include Rails.application.routes.url_helpers # # Take the FactoryGirl out of FactoryGirl.create config.include FactoryGirl::Syntax::Methods </code></pre> <p>end</p> <p>I'm using Rails 4.0.0.rc1, Ruby 1.9.3, FactoryGirl and rspec-rails 2.13.0 Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload