Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all specs in order determined by seed in rspec

I've noticed a couple specs that are failing intermittently depending on the order they're run.

To isolate them I'm looking for a command where I can enter the seed number and see all the specs listed with line numbers in the order determined by the seed number. Is this possible? using --format=documentation did not provide the info needed.

From there I will note the list of tests run BEFORE the intermittent failure each time it occurs and eventually narrow down to my culprit.

like image 521
UserDuser Avatar asked Apr 27 '15 21:04

UserDuser


1 Answers

RSpec's JSON formatter outputs the filenames and line numbers in the order they were run:

rspec --seed 1 -f json > out.json

To get just the list of filenames with line numbers from the resulting out.json file:

require 'json'
data = JSON.parse(File.read('out.json'))
examples = data['examples'].map do |example| 
  "#{example['file_path']}:#{example['line_number']}"
end

Now examples will contain an array of file paths like:

["./spec/models/user_spec.rb:19", "spec/models/user_spec.rb:29"]
like image 93
infused Avatar answered Sep 21 '22 16:09

infused