Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing rspec 2 tests into 'unit' and 'integration' categories in rails

How to organize rspec 2 tests into 'unit' (fast) and 'integration' (slow) categories?

  • I want to be able to run all unit tests with just rspec command, but not the 'integration' tests.
  • I want to be able to run only 'integration' tests.
like image 537
Evgenii Avatar asked Apr 05 '12 13:04

Evgenii


1 Answers

We have groups of the same nature. We run then one by one both on the local dev boxes and on the CI.

you can simply do

bundle exec rake spec:unit
bundle exec rake spec:integration
bundle exec rake spec:api

This is what our spec.rake looks like

  namespace :spec do
    RSpec::Core::RakeTask.new(:unit) do |t|
      t.pattern = Dir['spec/*/**/*_spec.rb'].reject{ |f| f['/api/v1'] || f['/integration'] }
    end

    RSpec::Core::RakeTask.new(:api) do |t|
      t.pattern = "spec/*/{api/v1}*/**/*_spec.rb"
    end

    RSpec::Core::RakeTask.new(:integration) do |t|
      t.pattern = "spec/integration/**/*_spec.rb"
    end
  end
like image 185
KensoDev Avatar answered Sep 25 '22 16:09

KensoDev