MattAndreko.com

"hostess is a code-slaying dragon found deep within the core of the earth, unearthing magma and vulnerabilities single handedly while using the other hand to pet his cat"

Installing Guard Gem Causes Tests to Fail - Solved

| Comments

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:

1
2
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:

1
2
3
gem 'guard-spork'
gem 'guard-rspec'
gem 'guard-cucumber'

Then to configure guard, I ran:

1
2
3
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:

1
DatabaseCleaner.strategy = :transaction

Everything seemed to work correctly when I changed it to (in both places):

1
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.

Comments