Search code examples
ruby-on-railsrubyrspecbundle

Is there a way to keep the order of cases as defined, while running bundle exec rspec {file_path} --format documentation?


I am having a problem while running

bundle exec rspec spec/services/abc_service_spec.rb --format documentation

The output of it, is not in the same order as the order of cases defined in the file. Is there any option to pass with while running rspec command ?


Solution

  • According to the documentation, Rspec uses the --order option to order the files, groups, and examples. The available ordering options are defined and rand while defined is the default options.

    If somehow your Rspec order option has changed, then run the rspec with --order defined like

    exec rspec spec/services/abc_service_spec.rb --format documentation --order defined
    

    If you want to set it globally then add below code to your spec_helper.rb

    Rspec.configure do |config|
      config.order = :defined
    end
    

    Hope you found this helpful.