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-06 19:30:59 +0300
committerRémy Coutable <remy@rymai.me>2018-04-10 16:38:40 +0300
commit5bef32195b3d4a0062564af4dc5c0a6e56b10faf (patch)
treeb48428181940d3621e03f3fae61711cb4d9b7643 /lib/rspec_flaky
parent9d220da84117220317ccff1421a394185fefe859 (diff)
Introduce RspecFlaky::ExamplesPruner to prune old flaky examples
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/rspec_flaky')
-rw-r--r--lib/rspec_flaky/examples_pruner.rb25
-rw-r--r--lib/rspec_flaky/flaky_examples_collection.rb2
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/rspec_flaky/examples_pruner.rb b/lib/rspec_flaky/examples_pruner.rb
new file mode 100644
index 00000000000..de6cf30d8ee
--- /dev/null
+++ b/lib/rspec_flaky/examples_pruner.rb
@@ -0,0 +1,25 @@
+require 'json'
+
+module RspecFlaky
+ class ExamplesPruner
+ # - flaky_examples: contains flaky examples
+ attr_reader :flaky_examples
+
+ def initialize(collection)
+ unless collection.is_a?(RspecFlaky::FlakyExamplesCollection)
+ raise ArgumentError, "`collection` must be a RspecFlaky::FlakyExamplesCollection, #{collection.class} given!"
+ end
+
+ @flaky_examples = collection
+ end
+
+ def prune_examples_older_than(date)
+ updated_hash = flaky_examples.dup
+ .delete_if do |uid, hash|
+ hash[:last_flaky_at] && Time.parse(hash[:last_flaky_at]).to_i < date.to_i
+ end
+
+ RspecFlaky::FlakyExamplesCollection.new(updated_hash)
+ end
+ end
+end
diff --git a/lib/rspec_flaky/flaky_examples_collection.rb b/lib/rspec_flaky/flaky_examples_collection.rb
index 973c95b0212..27a2845fb50 100644
--- a/lib/rspec_flaky/flaky_examples_collection.rb
+++ b/lib/rspec_flaky/flaky_examples_collection.rb
@@ -1,5 +1,7 @@
require 'json'
+require_relative 'flaky_example'
+
module RspecFlaky
class FlakyExamplesCollection < SimpleDelegator
def self.from_json(json)