Ash
Ash

Reputation: 25642

How to setup RSpec to test features last and only if all other tests pass

Like a lot of non-greenfeild projects, I arrived at my new job to find that most tests are performed using feature specs and not controller/model specs. Naturally this means that the tests take a really long time to execute.

Is there a way I can setup RSpec so that my feature tests run last - and they will only run if all other tests first succeed. I am migrating the application over to controller tests to speed execution, but there is no need to wait the 15mins for the feature tests to complete if there is an issue with model validation or one of my controllers is busted.

Is what I want to do possible?

(I am running the tests in RubyMine at the moment; but I can move to rake spec if need be).

Upvotes: 4

Views: 340

Answers (1)

David
David

Reputation: 3610

Although I haven't actually tried this myself, reading through the documentation it appears it is possible to do what you wish.

Add the following to your spec_helper.rb to override the global ordering and force rspec to fail on first failure.

RSpec.configure do |config|
  config.register_ordering :global do |examples|
    feature, other = examples.partition do |example|
      example.metadata[:type] == :feature
    end
    other + feature
  end

  config.fail_fast = true
end

Upvotes: 5

Related Questions