Rake::Rspec

Gem Version

Common Rake tasks for Rspec testing.

Quickly write a Rakefile for running a suite of Rspec tests, and ensure your suite has a proper structure.

Installation

Add this line to your application's Gemfile:

gem 'rake-rspec'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rake-rspec

Usage

Require the gem in your Rakefile:

require 'rake/rspec'

Structure your spec/ directory as follows:

my-project
├── spec/
    ├── spec_helper.rb
    ├── integration/
        ├── spec_helper.rb
  • All unit tests go into spec/.
  • All integration tests go into spec/integration/.

You then have access to three commands:

  1. rake spec - runs all unit tests.
  2. rake integration - runs all integrations tests.
  3. rake all - runs all tests.

Spec Helper (Optional)

To make sure that your unit tests aren't slowed down by any of your integration test dependencies, I suggest having two spec_helper.rb files - one for each type of test. Located as follows:

  • Unit tests require spec/spec_helper.rb.
  • Integration tests require spec/integration/spec_helper.rb.

The integration test spec_helper.rb should require the unit test spec_helper.rb, thus inheriting the vast majority of dependencies for your application.

Default Task (Optional)

The gem does not set a default task, this has to be done in your Rakefile. For example:

require 'rake/rspec'

task :default => :spec

Configuring Rspec (Optional)

The gem does not specify any options when running Rspec, this has to be implemented by adding a .rspec file to the root of your application. For example:

--color --format documentation --format=Nc 

The options above do the following:

  • Enable color in the output.
  • Format the output in a more verbose style.
  • Use the rspec-nc gem to display the result as an OSX Notification Center alert.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Create a new Pull Request.

Please create an issue if you find a bug or think of an enhancement that could be made.