phortx
phortx

Reputation: 919

RSpec: How to run the feature specs after all other specs

We have a rather complex integration spec setup with capybara and chrome. This leads to slow feature specs.

It would be nice if the feature specs would be executed after all other specs. Because it takes rather long time for a integration test to "boot" and find a bug which a simple request or unit test would have found way faster before.

Question: How to ensure that rspec runs the feature specs right after the other specs but sort them randomly be seed without breaking simplecov?

Upvotes: 2

Views: 722

Answers (1)

phortx
phortx

Reputation: 919

RSpec allows to setup a custom ordering. Following entry in the spec_helper.rb will cause rspec to run all other tests before the feature specs and order them randomly by the seed without breaking simplecov:

# Setup custom ordering to ensure that feature tests are executed after all other tests.
# Within this partition the tests are seed based randomly ordered.
config.register_ordering(:global) do |items|
  features, others = items.partition { |e| e.metadata[:type] == :feature }

  random_ordering = RSpec::Core::Ordering::Random.new(config)
  random_ordering.order(others) + random_ordering.order(features)
end

Please make sure not to have --order random in the rspec call or in the .rspec file

Upvotes: 4

Related Questions