I was tinkering with a new rails application, using RSpec2 and Cucumber for my testing. I was able to run all my tests by typing:
rake spec
rake cucumber
This worked perfectly, but every time I’d make a change, I’d have to run both commands. So I looked into the Guard gem, after watching the excellent RailsCast by Ryan Bates.
I started by adding to my gemfile:
gem 'guard-spork'
gem 'guard-rspec'
gem 'guard-cucumber'
Then to configure guard, I ran:
bundle
guard init rspec
guard init cucumber
So I went and ran the guard executable, only to see failures in both RSpec and Cucumber!
After much research, I found that my data was persisting between tests for some reason. I had the database_cleaner gem, so I didn’t understand why. I eventually found a line in both /spec/spec_helper.rb and /features/support/env.rb showing:
DatabaseCleaner.strategy = :transaction
Everything seemed to work correctly when I changed it to (in both places):
DatabaseCleaner.clean_with :truncation
I’m not exactly sure why this works. Maybe the transaction method doesn’t work well with sqlite, but it did manage to fix me up.