Class: RSpec::Bisect::Runner
- Inherits:
-
Object
- Object
- RSpec::Bisect::Runner
- Defined in:
- lib/rspec/bisect/runner.rb
Instance Attribute Summary collapse
-
#reporter ⇒ Object
Returns the value of attribute reporter.
-
#result_parser ⇒ Object
Returns the value of attribute result_parser.
Instance Method Summary collapse
- #examples_as_rspec_params(examples) ⇒ Object
- #execute! ⇒ Object
-
#initialize(reporter: reporter, result_parser: result_parser) ⇒ Runner
constructor
A new instance of Runner.
- #last_command_failed? ⇒ Boolean
- #last_command_passed? ⇒ Boolean
- #options ⇒ Object
- #progress_bar(additional_options) ⇒ Object
- #rspec_seed_argument ⇒ Object
- #run_examples(examples) ⇒ Object
- #run_examples_command(examples) ⇒ Object
Constructor Details
#initialize(reporter: reporter, result_parser: result_parser) ⇒ Runner
Returns a new instance of Runner.
11 12 13 14 |
# File 'lib/rspec/bisect/runner.rb', line 11 def initialize(reporter: reporter, result_parser: result_parser) self.reporter = reporter self.result_parser = result_parser end |
Instance Attribute Details
#reporter ⇒ Object
Returns the value of attribute reporter.
8 9 10 |
# File 'lib/rspec/bisect/runner.rb', line 8 def reporter @reporter end |
#result_parser ⇒ Object
Returns the value of attribute result_parser.
8 9 10 |
# File 'lib/rspec/bisect/runner.rb', line 8 def result_parser @result_parser end |
Instance Method Details
#examples_as_rspec_params(examples) ⇒ Object
50 51 52 |
# File 'lib/rspec/bisect/runner.rb', line 50 def examples_as_rspec_params(examples) examples.map { |e| "#{e['file_path']}:#{e['line_number']}" }.join ' ' end |
#execute! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rspec/bisect/runner.rb', line 16 def execute! @options = {} def @options end OptionParser.new do |opts| opts. = 'Usage: rspec-bisect [options]' opts.on('-s', '--seed N', Integer, 'Seed that causes order dependencies') do |s| [:seed] = s end opts.on('--help', 'Show this message') do puts opts exit end end.parse! reporter.seed [:seed] def rspec_seed_argument [:seed].nil? ? '' : "--seed #{[:seed]}" end result = Result.new `rspec --format json #{rspec_seed_argument}` parsed = result.as_json examples = parsed['examples'] failure_count = parsed['summary']['failure_count'] reporter.failing_tests failure_count failing_examples = examples.select { |e| e['status'] == 'failed' } def examples_as_rspec_params(examples) examples.map { |e| "#{e['file_path']}:#{e['line_number']}" }.join ' ' end def run_examples_command(examples) "rspec #{examples_as_rspec_params(examples)} #{rspec_seed_argument}" end def run_examples(examples) `#{run_examples_command(examples)}` end def last_command_passed? $?.exitstatus == 0 end def last_command_failed? not last_command_passed? end def () ProgressBar.create({format: '%t |%w>%i| %c/%C |%e'}.merge()) end dependent_examples_progress = title: 'Detecting Dependent Examples', total: failing_examples.size order_dependent_examples = failing_examples.select do |example| run_examples([example]) passed = last_command_passed? dependent_examples_progress.increment passed end reporter.order_dependent_examples order_dependent_examples order_dependent_examples.each do |example| reporter.determining_culprits example culprit_progress = title: 'Determining culprits', total: nil, format: '%t |%i| %c potential culprits' culprits = examples.take_while do |e| example['file_path'] != e['file_path'] || example['line_number'] != e['line_number'] end culprit_progress.progress = culprits.size culprit_count_theory = 1 while culprits.size > culprit_count_theory found_useless_group = false culprits.each_slice(culprits.size / (culprit_count_theory + 1)) do |excluded_culprits| culprit_progress.progress = culprits.size culprit_group = culprits - excluded_culprits run_examples culprit_group + [example] culprit_progress.progress = culprits.size if last_command_failed? culprits = culprit_group found_useless_group = true break end end culprit_count_theory += 1 unless found_useless_group end culprit_progress.stop reporter.culprits culprits, example reporter.report_failure run_examples_command culprits + [example] end end |
#last_command_failed? ⇒ Boolean
66 67 68 |
# File 'lib/rspec/bisect/runner.rb', line 66 def last_command_failed? not last_command_passed? end |
#last_command_passed? ⇒ Boolean
62 63 64 |
# File 'lib/rspec/bisect/runner.rb', line 62 def last_command_passed? $?.exitstatus == 0 end |
#options ⇒ Object
18 19 20 |
# File 'lib/rspec/bisect/runner.rb', line 18 def @options end |
#progress_bar(additional_options) ⇒ Object
70 71 72 |
# File 'lib/rspec/bisect/runner.rb', line 70 def () ProgressBar.create({format: '%t |%w>%i| %c/%C |%e'}.merge()) end |
#rspec_seed_argument ⇒ Object
37 38 39 |
# File 'lib/rspec/bisect/runner.rb', line 37 def rspec_seed_argument [:seed].nil? ? '' : "--seed #{[:seed]}" end |
#run_examples(examples) ⇒ Object
58 59 60 |
# File 'lib/rspec/bisect/runner.rb', line 58 def run_examples(examples) `#{run_examples_command(examples)}` end |
#run_examples_command(examples) ⇒ Object
54 55 56 |
# File 'lib/rspec/bisect/runner.rb', line 54 def run_examples_command(examples) "rspec #{examples_as_rspec_params(examples)} #{rspec_seed_argument}" end |