summaryrefslogtreecommitdiff
path: root/spec/lib/rspec_flaky
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-04-06 18:30:59 +0200
committerRémy Coutable <remy@rymai.me>2018-04-10 15:38:40 +0200
commit5bef32195b3d4a0062564af4dc5c0a6e56b10faf (patch)
treeb48428181940d3621e03f3fae61711cb4d9b7643 /spec/lib/rspec_flaky
parent9d220da84117220317ccff1421a394185fefe859 (diff)
downloadgitlab-ce-5bef32195b3d4a0062564af4dc5c0a6e56b10faf.tar.gz
Introduce RspecFlaky::ExamplesPruner to prune old flaky examples
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib/rspec_flaky')
-rw-r--r--spec/lib/rspec_flaky/examples_pruner_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/lib/rspec_flaky/examples_pruner_spec.rb b/spec/lib/rspec_flaky/examples_pruner_spec.rb
new file mode 100644
index 00000000000..40a086e92cb
--- /dev/null
+++ b/spec/lib/rspec_flaky/examples_pruner_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe RspecFlaky::ExamplesPruner, :aggregate_failures do
+ let(:collection_hash) do
+ {
+ a: { example_id: 'spec/foo/bar_spec.rb:2' },
+ b: { example_id: 'spec/foo/baz_spec.rb:3', first_flaky_at: Time.utc(2000, 1, 1).to_s, last_flaky_at: Time.utc(2000, 2, 1).to_s }
+ }
+ end
+
+ describe '#initialize' do
+ it 'accepts a collection' do
+ expect { described_class.new(RspecFlaky::FlakyExamplesCollection.new(collection_hash)) }.not_to raise_error
+ end
+
+ it 'does not accept anything else' do
+ expect { described_class.new([1, 2, 3]) }.to raise_error(ArgumentError, "`collection` must be a RspecFlaky::FlakyExamplesCollection, Array given!")
+ end
+ end
+
+ describe '#prune_examples_older_than' do
+ it 'returns a new collection without the examples older than 3 months' do
+ collection = RspecFlaky::FlakyExamplesCollection.new(collection_hash)
+
+ new_report = collection.to_report.dup.tap { |r| r.delete(:b) }
+ new_collection = described_class.new(collection).prune_examples_older_than(3.months.ago)
+
+ expect(new_collection).to be_a(RspecFlaky::FlakyExamplesCollection)
+ expect(new_collection.to_report).to eq(new_report)
+ expect(collection).to have_key(:b)
+ end
+ end
+end