Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 233
Ash Avatar asked Sep 10 '25 16:09

Ash


1 Answers

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
like image 61
David Avatar answered Sep 13 '25 07:09

David