organizing your specs into groups and running them separately

A while back I answered this StackOverflow question.

When you have a lot of specs, it makes sense to run them in separate logical groups and not just with rspec spec or something like that.

This way, you can save time and you can also run them in separate processes on the CI.

For example:

1
2
3
bundle exec rake spec:unit
bundle exec rake spec:integration
bundle exec rake spec:api

In order to achieve this, you need to change the spec.rake file.

1
2
3
4
5
6
7
8
9
10
11
12
13
  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

You can continue customizing that all you want, you can run specific specs that are the most important to you.

I find those groups useful for most of my use cases, but with minor changes you can make it fit yours

Using Rspec Tags

You can use tags for that as well, but I find that more tedious and you can forget to tag something.

For example:

1
2
3
  it "should do some integration test", :integration => true do
   # something
  end
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com