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:
authorRémy Coutable <remy@rymai.me>2018-04-10 14:22:19 +0300
committerRémy Coutable <remy@rymai.me>2018-04-10 16:38:40 +0300
commitb11e887582882bcf9c1787e18ccf34747ae50f91 (patch)
tree3eebc627a3cceceb4454664be059e2b75c7dd071 /lib/rspec_flaky/listener.rb
parent9bb97abf041d7aa17fc72b850ecc1695c1bad0f5 (diff)
Improve the architecture of RspecFlaky classes by introducing a new RspecFlaky::Report class
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/rspec_flaky/listener.rb')
-rw-r--r--lib/rspec_flaky/listener.rb39
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/rspec_flaky/listener.rb b/lib/rspec_flaky/listener.rb
index 4a5bfec9967..5b5e4f7c7de 100644
--- a/lib/rspec_flaky/listener.rb
+++ b/lib/rspec_flaky/listener.rb
@@ -1,5 +1,11 @@
require 'json'
+require_relative 'config'
+require_relative 'example'
+require_relative 'flaky_example'
+require_relative 'flaky_examples_collection'
+require_relative 'report'
+
module RspecFlaky
class Listener
# - suite_flaky_examples: contains all the currently tracked flacky example
@@ -9,7 +15,7 @@ module RspecFlaky
attr_reader :suite_flaky_examples, :flaky_examples
def initialize(suite_flaky_examples_json = nil)
- @flaky_examples = FlakyExamplesCollection.new
+ @flaky_examples = RspecFlaky::FlakyExamplesCollection.new
@suite_flaky_examples = init_suite_flaky_examples(suite_flaky_examples_json)
end
@@ -18,47 +24,36 @@ module RspecFlaky
return unless current_example.attempts > 1
- flaky_example = suite_flaky_examples.fetch(current_example.uid) { FlakyExample.new(current_example) }
+ flaky_example = suite_flaky_examples.fetch(current_example.uid) { RspecFlaky::FlakyExample.new(current_example) }
flaky_example.update_flakiness!(last_attempts_count: current_example.attempts)
flaky_examples[current_example.uid] = flaky_example
end
def dump_summary(_)
- write_report_file(flaky_examples, RspecFlaky::Config.flaky_examples_report_path)
+ RspecFlaky::Report.new(flaky_examples).write(RspecFlaky::Config.flaky_examples_report_path)
+ # write_report_file(flaky_examples, RspecFlaky::Config.flaky_examples_report_path)
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(new_flaky_examples.to_report)
+ Rails.logger.warn JSON.pretty_generate(new_flaky_examples.to_h)
- write_report_file(new_flaky_examples, RspecFlaky::Config.new_flaky_examples_report_path)
+ RspecFlaky::Report.new(new_flaky_examples).write(RspecFlaky::Config.new_flaky_examples_report_path)
+ # write_report_file(new_flaky_examples, RspecFlaky::Config.new_flaky_examples_report_path)
end
end
- def to_report(examples)
- Hash[examples.map { |k, ex| [k, ex.to_h] }]
- end
-
private
def init_suite_flaky_examples(suite_flaky_examples_json = nil)
- unless suite_flaky_examples_json
+ if suite_flaky_examples_json
+ RspecFlaky::Report.load_json(suite_flaky_examples_json).flaky_examples
+ else
return {} unless File.exist?(RspecFlaky::Config.suite_flaky_examples_report_path)
- suite_flaky_examples_json = File.read(RspecFlaky::Config.suite_flaky_examples_report_path)
+ RspecFlaky::Report.load(RspecFlaky::Config.suite_flaky_examples_report_path).flaky_examples
end
-
- FlakyExamplesCollection.from_json(suite_flaky_examples_json)
- end
-
- 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(examples_collection.to_report))
end
end
end