Insomnia
Setting up Rspec & Rails
Along with my new setup for a Rails / PostgreSQL application, I have included RSpec tests instead of the default test:unit.
I always seem to have difficulty remembering the steps to get RSpec tests generated as part of ‘rails generate’ and getting autotest to work. These steps work on both Windows, Mac and probably Linux
Rspec
- Use —skip-test-unit as an argument on the rails new command.
- Include gem ‘rspec-rails’, ‘2.8.1’ in the Gemfile
- Run bundle install.
- Run rails generate rspec:install
This will generate a spec/directory and a spec/spec_helper.rb file. Run bundle exec rspec spec/ now and you’ll see test output (even though there aren’t any tests yet).
Autotest
Autotest on Windows XP won’t show any output if no tests have been created. To me, I thought it was hung. Once I ran rails generate model grain name:text:, then Autotest produced output from the generated specs.
Something I didn’t have to do:
- At some point I installed ZenTest with gem. Consequently gemtest works, but bundle exec autotest doesn’t since I don’t have ZenTest in my GemFile. Once I put ZenTest in my Gemfile, Autotest works as I expect.
gem 'ZenTest', '4.6.2'
Extras
On Mac, you can install Growl support and fsevent by including those gems in your Gemfile and then creating a
require 'autotest/fsevent' require 'growl'
On Linux, use iNotify. Add
autotest-inotifyto Gemfile and
require ‘autotest/inotify’to .autotest