Class: SlowSpecFormatter
- Inherits:
-
Object
- Object
- SlowSpecFormatter
- Defined in:
- lib/rspec/watchdog/slow_spec_formatter.rb
Instance Method Summary collapse
- #dump_summary(summary) ⇒ Object
-
#initialize(output) ⇒ SlowSpecFormatter
constructor
A new instance of SlowSpecFormatter.
Constructor Details
#initialize(output) ⇒ SlowSpecFormatter
Returns a new instance of SlowSpecFormatter.
8 9 10 11 12 13 14 15 |
# File 'lib/rspec/watchdog/slow_spec_formatter.rb', line 8 def initialize(output) @output = output @show_logs = Rspec::Watchdog.config.show_logs @flaky_spec_detection = RSpec.configuration.flaky_spec_detection @watchdog_api_url = Rspec::Watchdog.config.watchdog_api_url @watchdog_api_token = Rspec::Watchdog.config.watchdog_api_token @fast_specs_threshold = RSpec.configuration.fast_specs_threshold end |
Instance Method Details
#dump_summary(summary) ⇒ Object
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 |
# File 'lib/rspec/watchdog/slow_spec_formatter.rb', line 17 def dump_summary(summary) if @show_logs puts "\nAll examples sorted by run time (most durable to fastest):" end all_examples = summary.examples.map do |example| { description: example.full_description, file_path: example.[:file_path], location: example.[:location], run_time: example.execution_result.run_time, status: example.execution_result.status.to_s, error_message: example.execution_result.exception ? example.execution_result.exception. : nil, flaky: example.[:flaky] || false } end if @fast_specs_threshold all_examples = all_examples.select { |ex| ex[:run_time] > @fast_specs_threshold && !ex[:flaky] } end sorted_examples = all_examples.sort_by { |ex| -ex[:run_time] } sorted_examples.each do |ex| puts "#{ex[:description]} (#{ex[:file_path]}) - #{ex[:run_time]} seconds - #{ex[:location]}" end if @show_logs calculate_average_time(summary) fastest_test(sorted_examples) slowest_test(sorted_examples) percentiles(sorted_examples) failed_tests(summary) tests_grouped_by_file(sorted_examples) tests_that_tooked_longer_than(sorted_examples, 2.0) time_distribution_analysis(sorted_examples) test_stability_analysis(summary) execution_time_variance(sorted_examples) temporal_complexity_analysis(sorted_examples) test_dependency_analysis(sorted_examples) end return unless @watchdog_api_url && @watchdog_api_token send_to_api(sorted_examples) end |