2017-07-19 13:51:59 -04:00
|
|
|
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,
|
2017-10-04 07:01:48 -04:00
|
|
|
flaky_reports: 0)
|
2017-07-19 13:51:59 -04:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-04 07:01:48 -04:00
|
|
|
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
|
2017-07-19 13:51:59 -04:00
|
|
|
|
2017-10-04 07:01:48 -04:00
|
|
|
if ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID']
|
|
|
|
self.last_flaky_job = "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}"
|
|
|
|
end
|
2017-07-19 13:51:59 -04:00
|
|
|
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
|