views:

64

answers:

1

How do I turn off transactional fixtures for only one spec (or Steak scenario) with RSpec 2? I tried some things found on the web without any success.

This leads to an undefined method exception.

describe "MyClass without transactional fixtures" do
  self.use_transactional_fixtures = false
  ...
end

This simply does nothing (transactional fixture is still on):

describe "MyClass without transactional fixtures" do
  RSpec.configure do |config|
    config.use_transactional_fixtures = false
  end
  ...
end

What else could I try?

+1  A: 

This used to be a bug (see ticket #197), but I seems to be okay now. I just don't know if it will work on a per test base (probably not). If you want to do this, you can disable transactional fixtures globally by putting config.use_transactional_fixtures = false on the spec_helper.rb and use DatabaseCleaner to set that.

I've had a similar 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

Lailson Bandeira
Thanks for pointing me to the ticket, Lailson. Answer accepted :-) I also use a workaround as I don't like to disable transactional fixtures globally (too slow). I simply do a MyClass.connection.commit_db_transaction() after the objects were created. Then I do the test and afterwards delete the database entries. That works fine, and all other tests still use the transactional feature.
Zardoz
Nice. As I said, you can do this cleanly with DatabaseCleaner (see the github repo README I pointed to know how to do this). But your solution is viable too, just a bit error-prone. But if it's working and you're satisfied, cool… =)
Lailson Bandeira