Thursday, February 28, 2013

Rake task for rspec:features

I'm using Capybara, rspec and poltergeist to test features/requests in Ruby on Rails

I wanted a simple raketask to check the features without typing:
$ rake spec SPEC=spec/features/**/*_spec.rb

I wanted to type:

$ rake spec:features

Creating the new raketask is quite simple:

desc "Run the code examples in spec/features"
task "spec:features" do
  Rails.env = ENV['RAILS_ENV'] = 'test'
  ENV['SPEC'] = "spec/features/**/*_spec.rb"
  Rake::Task['spec'].invoke
end
Note that the spec is set as an ENV variable and not passed as an argument to the invoke command.