Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rspec_flaky/listener.rb')
-rw-r--r--lib/rspec_flaky/listener.rb46
1 files changed, 11 insertions, 35 deletions
diff --git a/lib/rspec_flaky/listener.rb b/lib/rspec_flaky/listener.rb
index 4752ebe6410..4a5bfec9967 100644
--- a/lib/rspec_flaky/listener.rb
+++ b/lib/rspec_flaky/listener.rb
@@ -9,7 +9,7 @@ module RspecFlaky
attr_reader :suite_flaky_examples, :flaky_examples
def initialize(suite_flaky_examples_json = nil)
- @flaky_examples = {}
+ @flaky_examples = FlakyExamplesCollection.new
@suite_flaky_examples = init_suite_flaky_examples(suite_flaky_examples_json)
end
@@ -25,14 +25,14 @@ module RspecFlaky
end
def dump_summary(_)
- write_report_file(flaky_examples, flaky_examples_report_path)
+ write_report_file(flaky_examples, RspecFlaky::Config.flaky_examples_report_path)
- new_flaky_examples = _new_flaky_examples
+ new_flaky_examples = flaky_examples - suite_flaky_examples
if new_flaky_examples.any?
Rails.logger.warn "\nNew flaky examples detected:\n"
- Rails.logger.warn JSON.pretty_generate(to_report(new_flaky_examples))
+ Rails.logger.warn JSON.pretty_generate(new_flaky_examples.to_report)
- write_report_file(new_flaky_examples, new_flaky_examples_report_path)
+ write_report_file(new_flaky_examples, RspecFlaky::Config.new_flaky_examples_report_path)
end
end
@@ -44,45 +44,21 @@ module RspecFlaky
def init_suite_flaky_examples(suite_flaky_examples_json = nil)
unless suite_flaky_examples_json
- return {} unless File.exist?(suite_flaky_examples_report_path)
+ return {} unless File.exist?(RspecFlaky::Config.suite_flaky_examples_report_path)
- suite_flaky_examples_json = File.read(suite_flaky_examples_report_path)
+ suite_flaky_examples_json = File.read(RspecFlaky::Config.suite_flaky_examples_report_path)
end
- suite_flaky_examples = JSON.parse(suite_flaky_examples_json)
-
- Hash[(suite_flaky_examples || {}).map { |k, ex| [k, FlakyExample.new(ex)] }].freeze
- end
-
- def _new_flaky_examples
- flaky_examples.reject { |uid, _| already_flaky?(uid) }
- end
-
- def already_flaky?(example_uid)
- suite_flaky_examples.key?(example_uid)
+ FlakyExamplesCollection.from_json(suite_flaky_examples_json)
end
- def write_report_file(examples, file_path)
- return unless ENV['FLAKY_RSPEC_GENERATE_REPORT'] == 'true'
+ def write_report_file(examples_collection, file_path)
+ return unless RspecFlaky::Config.generate_report?
report_path_dir = File.dirname(file_path)
FileUtils.mkdir_p(report_path_dir) unless Dir.exist?(report_path_dir)
- File.write(file_path, JSON.pretty_generate(to_report(examples)))
- end
-
- def suite_flaky_examples_report_path
- @suite_flaky_examples_report_path ||= ENV['SUITE_FLAKY_RSPEC_REPORT_PATH'] ||
- Rails.root.join("rspec_flaky/suite-report.json")
- end
-
- def flaky_examples_report_path
- @flaky_examples_report_path ||= ENV['FLAKY_RSPEC_REPORT_PATH'] ||
- Rails.root.join("rspec_flaky/report.json")
- end
- def new_flaky_examples_report_path
- @new_flaky_examples_report_path ||= ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] ||
- Rails.root.join("rspec_flaky/new-report.json")
+ File.write(file_path, JSON.pretty_generate(examples_collection.to_report))
end
end
end