Class: FailSpell::RspecJsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/failspell/rspec_json_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_str) ⇒ RspecJsonParser

Returns a new instance of RspecJsonParser.



5
6
7
# File 'lib/failspell/rspec_json_parser.rb', line 5

def initialize(input_str)
  @input_str = input_str
end

Instance Attribute Details

#input_strObject (readonly)

Returns the value of attribute input_str.



3
4
5
# File 'lib/failspell/rspec_json_parser.rb', line 3

def input_str
  @input_str
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/failspell/rspec_json_parser.rb', line 9

def parse
  results = JSON.parse(input_str)
  failed_specs = results['examples'].select { |e| e['status'] == 'failed' }

  failed_specs.each_with_index do |spec, i|
    say "(#{i+1}) #{spec['full_description']}"
    say "    #{spec['file_path']}:#{spec['line_number']}".red
  end

  prompt = "Which one would you like to re-run? (1-#{failed_specs.count})"
  rerun = ask(prompt, Integer)
  selected_spec = failed_specs[rerun - 1]
  spec_path = "#{selected_spec['file_path']}:#{selected_spec['line_number']}"
  puts "Re-Running rspec #{spec_path}".yellow
  SpecRunner.new(spec_path).run
end