2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
require_relative '../../support/time_travel'
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
require_relative '../../../tooling/rspec_flaky/flaky_examples_collection'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
RSpec.describe RspecFlaky::FlakyExamplesCollection, :aggregate_failures, :freeze_time do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:collection_hash) do
|
|
|
|
{
|
|
|
|
a: { example_id: 'spec/foo/bar_spec.rb:2' },
|
|
|
|
b: { example_id: 'spec/foo/baz_spec.rb:3' }
|
|
|
|
}
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:collection_report) do
|
|
|
|
{
|
|
|
|
a: {
|
|
|
|
example_id: 'spec/foo/bar_spec.rb:2',
|
2022-01-26 12:08:38 +05:30
|
|
|
first_flaky_at: Time.now,
|
|
|
|
last_flaky_at: Time.now,
|
|
|
|
last_flaky_job: nil,
|
|
|
|
flaky_reports: 0,
|
|
|
|
last_attempts_count: nil
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
|
|
|
b: {
|
|
|
|
example_id: 'spec/foo/baz_spec.rb:3',
|
2022-01-26 12:08:38 +05:30
|
|
|
first_flaky_at: Time.now,
|
|
|
|
last_flaky_at: Time.now,
|
|
|
|
last_flaky_job: nil,
|
|
|
|
flaky_reports: 0,
|
|
|
|
last_attempts_count: nil
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'accepts no argument' do
|
|
|
|
expect { described_class.new }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts a hash' do
|
|
|
|
expect { described_class.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 Hash, Array given!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
describe '#to_h' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'calls #to_h on the values' do
|
|
|
|
collection = described_class.new(collection_hash)
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(collection.to_h).to eq(collection_report)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#-' do
|
|
|
|
it 'returns only examples that are not present in the given collection' do
|
|
|
|
collection1 = described_class.new(collection_hash)
|
|
|
|
collection2 = described_class.new(
|
|
|
|
a: { example_id: 'spec/foo/bar_spec.rb:2' },
|
|
|
|
c: { example_id: 'spec/bar/baz_spec.rb:4' })
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect((collection2 - collection1).to_h).to eq(
|
2018-03-17 18:26:18 +05:30
|
|
|
c: {
|
|
|
|
example_id: 'spec/bar/baz_spec.rb:4',
|
2022-01-26 12:08:38 +05:30
|
|
|
first_flaky_at: Time.now,
|
|
|
|
last_flaky_at: Time.now,
|
|
|
|
last_flaky_job: nil,
|
|
|
|
flaky_reports: 0,
|
|
|
|
last_attempts_count: nil
|
2018-03-17 18:26:18 +05:30
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails if the given collection does not respond to `#key?`' do
|
|
|
|
collection = described_class.new(collection_hash)
|
|
|
|
|
|
|
|
expect { collection - [1, 2, 3] }.to raise_error(ArgumentError, "`other` must respond to `#key?`, Array does not!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|