diff options
author | Rémy Coutable <remy@rymai.me> | 2017-10-04 14:01:48 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-10-04 16:14:38 +0300 |
commit | ebfb5a50757b65530e9649815619ec206513c65e (patch) | |
tree | c61b31e1f84989a6ef48f17cb428ee9b32a93956 /lib/rspec_flaky/flaky_example.rb | |
parent | 4a0f720a502ac02423cb9db20727ba386de3e1f1 (diff) |
Ensure RSpecFlaky doesn't automatically update flaky examples
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>
Diffstat (limited to 'lib/rspec_flaky/flaky_example.rb')
-rw-r--r-- | lib/rspec_flaky/flaky_example.rb | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/rspec_flaky/flaky_example.rb b/lib/rspec_flaky/flaky_example.rb index f81fb90e870..6be24014d89 100644 --- a/lib/rspec_flaky/flaky_example.rb +++ b/lib/rspec_flaky/flaky_example.rb @@ -9,24 +9,21 @@ module RspecFlaky line: example.line, description: example.description, last_attempts_count: example.attempts, - flaky_reports: 1) + flaky_reports: 0) else super end end - def first_flaky_at - self[:first_flaky_at] || Time.now - end - - def last_flaky_at - Time.now - 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 - def last_flaky_job - return unless ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID'] - - "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}" + 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 |