RSpec and Webrat for Rails Integration Testing
Getting RSpec and Webrat to cooperate has gotten a bit easier recently, so make sure you have all the latest versions of the webrat, rspec and rspec-rails gems installed. Some quirks remain which might trip you up coming from TestUnit. For example if you
cd spec/integration
and
spec ./user_integration_spec.rb
or
ruby ./user_integration_spec.rb
you might get
undefined method `visit (…)
while a similar procedure would run fine in test/integration with TestUnit
But with RSpec, when you run
spec ./spec/integration/user_integration_spec.rb
or
rake spec:integration
all is well. It seems you have to stand at least in the spec directory or above, otherwise the block
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
in spec_helper.rb will not run correctly.
So remember that RSpec is a bit less forgiving than TestUnit in how your tests are called.
It’s also important that you run
script/generate rspec
after installing RSpec to have the rake tasks “installed”.
Finally, his procedure will likely not be necessary with recent versions of Webrat and RSpec.
See here for a testing system for Rails that integrates RSpec and Webrat, it makes a lot of sense.
Posted: 08 June 2010