简体   繁体   中英

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs

 before(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = false
  end

  after(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = true
    clean_engine_database
  end

That now gives me the error:

 Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
     undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class

Is there a way to do this per test block in Rails 3 with Rspec 2?

I'm looking for the answer to this question, came across this blog entry

It suggests to declare inside the describe block

describe "xxx" do
  self.use_transactional_fixtures = false
  ...

I tried it with Rails 3.0.7 with RSpec 2.6.3, and looks like working.

You can disable transactional fixtures globally by putting config.use_transactional_fixtures = false on the spec_helper.rb. If you want to control them by test (eg use transactional just on some of them), you can set this behavior with DatabaseCleaner.

I've had a related problem when testing pages with javascript on the browser (a scenario that does not work with transactional fixtures). Here's how I managed to work around it: http://github.com/lailsonbm/contact_manager_app

RSpec.configure do |config|
  config.use_transactional_fixtures = true
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