Class: RSpecTracer::Runner
- Inherits:
-
Object
- Object
- RSpecTracer::Runner
- Defined in:
- lib/rspec_tracer/runner.rb
Constant Summary collapse
- EXAMPLE_RUN_REASON =
{ explicit_run: 'Explicit run', no_cache: 'No cache', interrupted: 'Interrupted previously', flaky_example: 'Flaky example', failed_example: 'Failed previously', pending_example: 'Pending previously', files_changed: 'Files changed' }.freeze
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
- #deregister_duplicate_examples ⇒ Object
- #generate_missed_coverage ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #non_zero_exit_code? ⇒ Boolean
- #on_example_failed(example_id, execution_result) ⇒ Object
- #on_example_passed(example_id, execution_result) ⇒ Object
- #on_example_pending(example_id, execution_result) ⇒ Object
- #on_example_skipped(example_id) ⇒ Object
- #register_deleted_examples ⇒ Object
- #register_dependency(examples_coverage) ⇒ Object
- #register_example(example) ⇒ Object
- #register_examples_coverage(examples_coverage) ⇒ Object
- #register_interrupted_examples ⇒ Object
- #register_untraced_dependency(trace_point_files) ⇒ Object
- #run_example?(example_id) ⇒ Boolean
- #run_example_reason(example_id) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
20 21 22 23 24 25 26 27 |
# File 'lib/rspec_tracer/runner.rb', line 20 def initialize @cache = RSpecTracer::Cache.new @reporter = RSpecTracer::Reporter.new @filtered_examples = {} @cache.load_cache_for_run filter_examples_to_run end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
18 19 20 |
# File 'lib/rspec_tracer/runner.rb', line 18 def cache @cache end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
18 19 20 |
# File 'lib/rspec_tracer/runner.rb', line 18 def reporter @reporter end |
Instance Method Details
#deregister_duplicate_examples ⇒ Object
45 46 47 |
# File 'lib/rspec_tracer/runner.rb', line 45 def deregister_duplicate_examples @reporter.deregister_duplicate_examples end |
#generate_missed_coverage ⇒ Object
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 |
# File 'lib/rspec_tracer/runner.rb', line 73 def generate_missed_coverage missed_coverage = Hash.new do |files_coverage, file_path| files_coverage[file_path] = Hash.new do |strength, line_number| strength[line_number] = 0 end end @cache.cached_examples_coverage.each_pair do |example_id, example_coverage| example_coverage.each_pair do |file_path, line_coverage| next if @reporter.example_interrupted?(example_id) || @reporter.duplicate_example?(example_id) next unless @reporter.example_skipped?(example_id) file_name = RSpecTracer::SourceFile.file_name(file_path) next if @reporter.file_deleted?(file_name) line_coverage.each_pair do |line_number, strength| missed_coverage[file_path][line_number] += strength end end end missed_coverage end |
#non_zero_exit_code? ⇒ Boolean
144 145 146 147 |
# File 'lib/rspec_tracer/runner.rb', line 144 def non_zero_exit_code? !@reporter.duplicate_examples.empty? && ENV.fetch('RSPEC_TRACER_FAIL_ON_DUPLICATES', 'true') == 'true' end |
#on_example_failed(example_id, execution_result) ⇒ Object
57 58 59 |
# File 'lib/rspec_tracer/runner.rb', line 57 def on_example_failed(example_id, execution_result) @reporter.on_example_failed(example_id, execution_result) end |
#on_example_passed(example_id, execution_result) ⇒ Object
53 54 55 |
# File 'lib/rspec_tracer/runner.rb', line 53 def on_example_passed(example_id, execution_result) @reporter.on_example_passed(example_id, execution_result) end |
#on_example_pending(example_id, execution_result) ⇒ Object
61 62 63 |
# File 'lib/rspec_tracer/runner.rb', line 61 def on_example_pending(example_id, execution_result) @reporter.on_example_pending(example_id, execution_result) end |
#on_example_skipped(example_id) ⇒ Object
49 50 51 |
# File 'lib/rspec_tracer/runner.rb', line 49 def on_example_skipped(example_id) @reporter.on_example_skipped(example_id) end |
#register_deleted_examples ⇒ Object
69 70 71 |
# File 'lib/rspec_tracer/runner.rb', line 69 def register_deleted_examples @reporter.register_deleted_examples(@cache.all_examples) end |
#register_dependency(examples_coverage) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rspec_tracer/runner.rb', line 100 def register_dependency(examples_coverage) filtered_files = Set.new examples_coverage.each_pair do |example_id, example_coverage| next if @reporter.example_interrupted?(example_id) || @reporter.duplicate_example?(example_id) register_example_files_dependency(example_id) example_coverage.each_key do |file_path| next if filtered_files.include?(file_path) filtered_files << file_path unless register_file_dependency(example_id, file_path) end end @reporter.pending_examples.each do |example_id| register_example_files_dependency(example_id) end end |
#register_example(example) ⇒ Object
41 42 43 |
# File 'lib/rspec_tracer/runner.rb', line 41 def register_example(example) @reporter.register_example(example) end |
#register_examples_coverage(examples_coverage) ⇒ Object
140 141 142 |
# File 'lib/rspec_tracer/runner.rb', line 140 def register_examples_coverage(examples_coverage) @reporter.register_examples_coverage(examples_coverage) end |
#register_interrupted_examples ⇒ Object
65 66 67 |
# File 'lib/rspec_tracer/runner.rb', line 65 def register_interrupted_examples @reporter.register_interrupted_examples end |
#register_untraced_dependency(trace_point_files) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rspec_tracer/runner.rb', line 121 def register_untraced_dependency(trace_point_files) untraced_files = generate_untraced_files(trace_point_files) untraced_files.each do |file_path| source_file = RSpecTracer::SourceFile.from_path(file_path) next if RSpecTracer.filters.any? { |filter| filter.match?(source_file) } @reporter.register_source_file(source_file) @reporter.all_examples.each_key do |example_id| next if @reporter.example_interrupted?(example_id) || @reporter.duplicate_example?(example_id) @reporter.register_dependency(example_id, source_file[:file_name]) end end end |
#run_example?(example_id) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/rspec_tracer/runner.rb', line 29 def run_example?(example_id) return true if explicit_run? !@cache.all_examples.key?(example_id) || @filtered_examples.key?(example_id) end |
#run_example_reason(example_id) ⇒ Object
35 36 37 38 39 |
# File 'lib/rspec_tracer/runner.rb', line 35 def run_example_reason(example_id) return EXAMPLE_RUN_REASON[:explicit_run] if explicit_run? @filtered_examples[example_id] || EXAMPLE_RUN_REASON[:no_cache] end |