Rails 3, RSpec and Cucumber setup
This quick how-to runs through creating a new Rails 3 application with both RSpec and Cucumber for testing (rather than Test::Unit).
Rails 3 requires (the somewhat confusingly versioned) RSpec 2 and rspec-rails. Similarly, Cucumber uses cucumber-rails for bootstrapping your Rails app and provides generators for creating features.
Install RSpec 2
sudo gem install rspec-rails --preInstall Cucumber
sudo gem install cucumber-railsCreate a new Rails 3 application
Ensure you have the latest version of Rails 3 installed then create a new application, skipping creation of the test directory since we’ll be using RSpec and Cucumber (with spec and features) instead.
rails new --skip-testunit Add rspec-rails to the :test and :development groups to the Gemfile.
group :test, :development do
gem 'rspec-rails', '>= 2.0.0.beta.22'
endAdd cucumber-rails and dependencies to the :cucumber group in the Gemfile:
group :cucumber do
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'spork'
gem 'launchy'
endEnsure all gems are installed by using Bundler:
sudo bundle installThen install the RSpec extensions (creates the spec directory and creates a rake task):
rails generate rspec:installNow we can specify that Rails itself uses RSpec when running generators by adding the following inside config/applicaton.rb:
config.generators do |g|
g.test_framework :rspec
endNext, bootstrap your Rails app, for Cucumber:
rails generate cucumber:install --rspec --capybaraThat’s it! Now the following rake tasks exist to execute your specs or cucumber features (by default rake will execute both).
rake spec
rake cucumberAbout this entry
You’re currently reading “Rails 3, RSpec and Cucumber setup,” an entry on Slash Dot Dash
- Published:
- 09.27.10 / 7pm
- Category:
- Ruby, Ruby on Rails

Comments are closed
Comments are currently closed on this entry.