Rake

Throughout this book, you’ve run your spec suite via the rspec command. But there’s another common way to run your specs: using the Rake build tool. The rspec-core gem ships with an easy-to-configure Rake task. To enable it, add the following two lines to your project’s Rakefile:

 require ​'rspec/core/rake_task'
 RSpec::Core::RakeTask.new(​:spec​)

This snippet defines a simple spec task that will run rspec with your configured defaults. You can then run it like so:

 $ ​​rake spec

Running RSpec this way adds some overhead. It takes time to load Rake itself, plus any libraries you need for other tasks in your Rakefile. A canned Rake task is also less flexible than the rspec command, ...

Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.