ebfb5a5075
Previously, instantiating a RspecFlaky::FlakyExample object would automatically update its first_flaky_at, last_flaky_at and last_flaky_job. That was wrong because we would overwrite every time the suite report with this false data. We now: - Get the suite report and only read from it - Write only the currently detected flaky examples in the report, so that the final report is only updated with flaky examples that were actually detected in each job. Before, job1 could overwrite the legit report from job2! - Write the newly detected flaky examples by rejecting the already tracked flaky specs instead of using another hash. Signed-off-by: Rémy Coutable <remy@rymai.me>
36 lines
1 KiB
Ruby
36 lines
1 KiB
Ruby
module RspecFlaky
|
|
# This represents a flaky RSpec example and is mainly meant to be saved in a JSON file
|
|
class FlakyExample < OpenStruct
|
|
def initialize(example)
|
|
if example.respond_to?(:example_id)
|
|
super(
|
|
example_id: example.example_id,
|
|
file: example.file,
|
|
line: example.line,
|
|
description: example.description,
|
|
last_attempts_count: example.attempts,
|
|
flaky_reports: 0)
|
|
else
|
|
super
|
|
end
|
|
end
|
|
|
|
def update_flakiness!(last_attempts_count: nil)
|
|
self.first_flaky_at ||= Time.now
|
|
self.last_flaky_at = Time.now
|
|
self.flaky_reports += 1
|
|
self.last_attempts_count = last_attempts_count if last_attempts_count
|
|
|
|
if ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID']
|
|
self.last_flaky_job = "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}"
|
|
end
|
|
end
|
|
|
|
def to_h
|
|
super.merge(
|
|
first_flaky_at: first_flaky_at,
|
|
last_flaky_at: last_flaky_at,
|
|
last_flaky_job: last_flaky_job)
|
|
end
|
|
end
|
|
end
|