diff options
author | Rémy Coutable <remy@rymai.me> | 2017-07-19 20:51:59 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-08-11 15:55:10 +0300 |
commit | 8f8fd342313b0cd459d2fedb5b461b0cc063f248 (patch) | |
tree | 87ea1fc1a405d1a0f50165e69e4f12508257d75a /lib/rspec_flaky/flaky_example.rb | |
parent | c62ae6cfd70d518386fdbcb9714d18ac4f5e8c31 (diff) |
Use a new RspecFlakyListener to detect flaky specs
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 | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/rspec_flaky/flaky_example.rb b/lib/rspec_flaky/flaky_example.rb new file mode 100644 index 00000000000..f81fb90e870 --- /dev/null +++ b/lib/rspec_flaky/flaky_example.rb @@ -0,0 +1,39 @@ +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: 1) + else + super + end + end + + def first_flaky_at + self[:first_flaky_at] || Time.now + end + + def last_flaky_at + Time.now + end + + def last_flaky_job + return unless ENV['CI_PROJECT_URL'] && ENV['CI_JOB_ID'] + + "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_JOB_ID']}" + 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 |