Wisdom Biscuit was my first Rails application. It’s hosted at Joyent (when they were still known as TextDrive) and runs on Rails 1.2.3.
I know, right?
With the imminent release of Rails 3, I decided to refresh the app and build it on the latest version, hosted over at Heroku. And since I recently finished reading The RSpec Book, I’ll attempt to drive it’s development from the outside-in (practicing BDD with Cucumber and RSpec.)
First, I’ll make sure my development environment is up-to-date, and run:
$ sudo gem update --system
$ sudo gem install rails --pre
$ sudo gem install bundler --pre
Rails 3 makes that easy.
File | New, or, Creating a fresh application
From the command line, run:
$ rails new -?
Amongst other usage flags, we see:
-J, [--skip-prototype] # Skip Prototype files
-T, [--skip-test-unit] # Skip Test::Unit files
$ rails new wisdombiscuit --skip-prototype --skip-test-unit
Dependency Management, or, Getting by with a little help from our friends
To use RSpec and Cucumber, first we explicitly define them as dependencies in the app’s
.gemfile (used by Bundler, as we’ll see in the next step):
group :test do
gem 'rspec', '>= 2.0.0.beta.19'
gem 'rspec-rails', '>= 2.0.0.beta.19'
gem 'cucumber', '>= 0.8.5'
gem 'cucumber-rails', '>= 0.3.2'
group block ensures they are only
required when the application is running within the specified environment, which in this case is the
test environment. Then we install those gems locally by running:
$ bundle install
And with any luck, you’ll see a list of all the gems scroll past as they’re downloaded and installed (or updated, if we had older versions of those gems already installed.) Now we’ll install Cucumber and RSpec folders & configuration files into our application by running:
$ rails generate rspec:install
$ rails generate cucumber:install --rspec --webrat
config/application.rb to tell Rails to generate new RSpec specs instead of Test::Unit unit tests whenever those generators are invoked:
# Configure generators values. Many other options are available, be sure to check the documentation.
config.generators do |g|
And that’s it for now: we opted-out of the default Test::Unit integration for our new Rails 3 application, declared our dependencies on RSpec and Cucumber & installed them locally, then configured our application to know how to generate features and specs going forward.
Let’s save our progress thus far and commit our changes in Git:
$ git init
$ git add .
$ git commit -a -m "new rails 3 app using RSpec and Cucumber"
$ git tag part1
(Feel free to fork my Github repository if you’d like to follow along at http://github.com/defeated/wisdombiscuit)
- Read Part 1 where we configure Rails 3 to use RSpec and Cucumber as the testing framework instead of Test::Unit
- Read Part 3 where we put it all together as an Application Template