Rspec (steak) turning off transactional fixtures

Hey all,

I have replaced Cucumber with Steak and I like the experience so far. It
is
not as polished as Cucumber in what comes to configuration, but it is
simpler and covers my needs perfectly. I’ve followed the trick to pass a
hash to the example in order to setup Capybara to use a different
driver,
like so:

spec/acceptance/support/javascript.rb

Spec::Runner.configure do |config|

config.before(:each) do
if options[:js] #using culerity
Capybara.current_driver = :culerity
config.use_transactional_fixtures = false
end
end

config.after(:each) do
if options[:js]
DatabaseCleaner.clean
Capybara.use_default_driver
config.use_transactional_fixtures = true
end
end

end

As you can see, if an example has an option with :js => true, it will
use
culerity, and this works fine. What doesn’t seem to work is the
use_transactional_fixtures = false conf. I still can’t access the data
outside of the ruby instance (i.e: the app server celerity is accessing
doesn’t have access to the fixture data). With Cucumber it would be a
matter
of setting up Cucumber::Rails::World.use_transactional_fixtures to
false.

How could I disable transactional fixtures on a per example base when
using
rspec / steak?

Thanks,

Marcelo.

Hi David,

Yeah, I’m using DatabaseCleaner, pretty much familiar with it.

The issue is that passing it to rspec’s yielded config object didn’t
seem to
disable transactional_fixtures:

Spec::Runner.configure do |config|

if  options[:js]
  DatabaseCleaner.clean
  Capybara.use_default_driver
  config.use_transactional_fixtures = true
end

end

end

Check the lines “config.use_transactional_fixtures” on both callbacks. I
doesn’t seem to disable them. Any ideas?

Marcelo.

On Jun 15, 2010, at 5:15 PM, Marcelo de Moraes S. wrote:

  Capybara.current_driver = :culerity

end

end

As you can see, if an example has an option with :js => true, it will use culerity, and this works fine. What doesn’t seem to work is the use_transactional_fixtures = false conf. I still can’t access the data outside of the ruby instance (i.e: the app server celerity is accessing doesn’t have access to the fixture data). With Cucumber it would be a matter of setting up Cucumber::Rails::World.use_transactional_fixtures to false.

How could I disable transactional fixtures on a per example base when using rspec / steak?

As far as I know, this is not easy, or maybe even possible, with the
Rails built-in framework. What I’d do is turn off the rails features
(config.use_transactional_fixtures = false) and use database_cleaner.
Are you familiar w/ database_cleaner?

David

On Jun 16, 2010, at 1:37 PM, Marcelo de Moraes S. wrote:

  Capybara.current_driver = :culerity
end

end

end

Check the lines “config.use_transactional_fixtures” on both callbacks. I doesn’t seem to disable them. Any ideas?

Not sure why that doesn’t work, but that’s not what I was proposing. I’m
saying use database cleaner instead of
config.use_transactional_fixtures:

Spec::Runner.configure do |c|
c.use_transactional_fixtures = false
c.before do
if options[:js]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
end
c.after do
DatabaseCleaner.clean
end
end

Make sense?

Yes,

That’s what I want to do, but my code is a little bit different. I’m
calling
config.use_transactional_fixtures inside the block:

config.before(:each) do
config.use_transactional_fixtures = false
end

And then enabling it again after:

config.after(:each) do
DatabaseCleaner.clean #truncation mode doesn’t require the start
method to
be called, so clean is enough.
config.use_transactional_fixtures = true
end

Why? Well, not all example use js (culerity), and for those, I wouldn’t
want
to use DatabaseCleaner.

However, it doesn’t seem to work. If I create an object from the ruby
instance running the specs, and put a breakpoint, I can’t see the data
outside of it :frowning:

Any ideas?

Marcelo.

On Jun 16, 2010, at 2:02 PM, Marcelo de Moraes S. wrote:

Yes,

That’s what I want to do, but my code is a little bit different. I’m calling config.use_transactional_fixtures inside the block:

This doesn’t work. That’s what I was saying. Probably because the
transactions is already turned on by active record before this block is
executed.

Read my last post again - it should solve your problem by using database
cleaner’s transaction mode for in-memory examples and truncation mode
for in-browser examples.

Oh, the code in the before/after blocks is wrapped in a if options[:js].
Forgot to write it.

On Wed, Jun 16, 2010 at 2:02 PM, Marcelo de Moraes S. <

Ah, got it!

Thanks for your patience, David :wink:

Cheers,

Marcelo.