diff options
Diffstat (limited to 'spec/tooling/rspec_flaky/flaky_example_spec.rb')
-rw-r--r-- | spec/tooling/rspec_flaky/flaky_example_spec.rb | 79 |
1 files changed, 21 insertions, 58 deletions
diff --git a/spec/tooling/rspec_flaky/flaky_example_spec.rb b/spec/tooling/rspec_flaky/flaky_example_spec.rb index 03436ee1cbd..511f3286f56 100644 --- a/spec/tooling/rspec_flaky/flaky_example_spec.rb +++ b/spec/tooling/rspec_flaky/flaky_example_spec.rb @@ -9,30 +9,14 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do include ActiveSupport::Testing::TimeHelpers include StubENV - let(:flaky_example_attrs) do + let(:example_attrs) do { example_id: 'spec/foo/bar_spec.rb:2', file: 'spec/foo/bar_spec.rb', line: 2, description: 'hello world', - first_flaky_at: 1234, - last_flaky_at: 2345, - last_flaky_job: 'https://gitlab.com/gitlab-org/gitlab-foss/-/jobs/12', last_attempts_count: 2, - flaky_reports: 1 - } - end - - let(:example_attrs) do - { - uid: 'abc123', - example_id: flaky_example_attrs[:example_id], - file: flaky_example_attrs[:file], - line: flaky_example_attrs[:line], - description: flaky_example_attrs[:description], - status: 'passed', - exception: 'BOOM!', - attempts: flaky_example_attrs[:last_attempts_count] + feature_category: :feature_category } end @@ -48,18 +32,19 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do it 'returns valid attributes' do attrs = flaky_example.to_h - expect(attrs[:uid]).to eq(flaky_example_attrs[:uid]) - expect(attrs[:file]).to eq(flaky_example_attrs[:file]) - expect(attrs[:line]).to eq(flaky_example_attrs[:line]) - expect(attrs[:description]).to eq(flaky_example_attrs[:description]) + expect(attrs[:uid]).to eq(example_attrs[:uid]) + expect(attrs[:file]).to eq(example_attrs[:file]) + expect(attrs[:line]).to eq(example_attrs[:line]) + expect(attrs[:description]).to eq(example_attrs[:description]) + expect(attrs[:feature_category]).to eq(example_attrs[:feature_category]) expect(attrs[:first_flaky_at]).to eq(expected_first_flaky_at) expect(attrs[:last_flaky_at]).to eq(expected_last_flaky_at) - expect(attrs[:last_attempts_count]).to eq(flaky_example_attrs[:last_attempts_count]) + expect(attrs[:last_attempts_count]).to eq(example_attrs[:last_attempts_count]) expect(attrs[:flaky_reports]).to eq(expected_flaky_reports) end end - context 'when given an Example hash' do + context 'when given an Example.to_h' do it_behaves_like 'a valid FlakyExample instance' do let(:args) { example_attrs } let(:expected_first_flaky_at) { Time.now } @@ -67,18 +52,9 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do let(:expected_flaky_reports) { 0 } end end - - context 'when given a FlakyExample hash' do - it_behaves_like 'a valid FlakyExample instance' do - let(:args) { flaky_example_attrs } - let(:expected_flaky_reports) { flaky_example_attrs[:flaky_reports] } - let(:expected_first_flaky_at) { flaky_example_attrs[:first_flaky_at] } - let(:expected_last_flaky_at) { flaky_example_attrs[:last_flaky_at] } - end - end end - describe '#update_flakiness!' do + describe '#update!' do shared_examples 'an up-to-date FlakyExample instance' do let(:flaky_example) { described_class.new(args) } @@ -86,18 +62,18 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do args[:first_flaky_at] = nil freeze_time do - flaky_example.update_flakiness! + flaky_example.update!(example_attrs) expect(flaky_example.to_h[:first_flaky_at]).to eq(Time.now) end end it 'maintains the first_flaky_at if exists' do - flaky_example.update_flakiness! + flaky_example.update!(example_attrs) expected_first_flaky_at = flaky_example.to_h[:first_flaky_at] travel_to(Time.now + 42) do - flaky_example.update_flakiness! + flaky_example.update!(example_attrs) expect(flaky_example.to_h[:first_flaky_at]).to eq(expected_first_flaky_at) end end @@ -105,7 +81,7 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do it 'updates the last_flaky_at' do travel_to(Time.now + 42) do the_future = Time.now - flaky_example.update_flakiness! + flaky_example.update!(example_attrs) expect(flaky_example.to_h[:last_flaky_at]).to eq(the_future) end @@ -114,16 +90,15 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do it 'updates the flaky_reports' do expected_flaky_reports = flaky_example.to_h[:first_flaky_at] ? flaky_example.to_h[:flaky_reports] + 1 : 1 - expect { flaky_example.update_flakiness! }.to change { flaky_example.to_h[:flaky_reports] }.by(1) + expect { flaky_example.update!(example_attrs) }.to change { flaky_example.to_h[:flaky_reports] }.by(1) expect(flaky_example.to_h[:flaky_reports]).to eq(expected_flaky_reports) end - context 'when passed a :last_attempts_count' do - it 'updates the last_attempts_count' do - flaky_example.update_flakiness!(last_attempts_count: 42) + it 'updates the last_attempts_count' do + example_attrs[:last_attempts_count] = 42 + flaky_example.update!(example_attrs) - expect(flaky_example.to_h[:last_attempts_count]).to eq(42) - end + expect(flaky_example.to_h[:last_attempts_count]).to eq(42) end context 'when run on the CI' do @@ -134,7 +109,7 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do end it 'updates the last_flaky_job' do - flaky_example.update_flakiness! + flaky_example.update!(example_attrs) expect(flaky_example.to_h[:last_flaky_job]).to eq(job_url) end @@ -146,12 +121,6 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do let(:args) { example_attrs } end end - - context 'when given a FlakyExample hash' do - it_behaves_like 'an up-to-date FlakyExample instance' do - let(:args) { flaky_example_attrs } - end - end end describe '#to_h', :freeze_time do @@ -160,7 +129,7 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do it 'returns a valid hash' do flaky_example = described_class.new(args) - final_hash = flaky_example_attrs.merge(additional_attrs) + final_hash = example_attrs.merge(additional_attrs) expect(flaky_example.to_h).to eq(final_hash) end @@ -175,11 +144,5 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do end end end - - context 'when given a FlakyExample hash' do - let(:args) { flaky_example_attrs } - - it_behaves_like 'a valid FlakyExample hash' - end end end |