2018-10-08 10:50:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-02-23 04:10:45 -05:00
|
|
|
require 'forwardable'
|
|
|
|
require 'digest'
|
|
|
|
|
2017-07-19 13:51:59 -04:00
|
|
|
module RspecFlaky
|
|
|
|
# This is a wrapper class for RSpec::Core::Example
|
|
|
|
class Example
|
2021-02-23 04:10:45 -05:00
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegators :execution_result, :status, :exception
|
2017-07-19 13:51:59 -04:00
|
|
|
|
|
|
|
def initialize(rspec_example)
|
2021-02-23 04:10:45 -05:00
|
|
|
@rspec_example = rspec_example.respond_to?(:example) ? rspec_example.example : rspec_example
|
2017-07-19 13:51:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def uid
|
|
|
|
@uid ||= Digest::MD5.hexdigest("#{description}-#{file}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_id
|
|
|
|
rspec_example.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
|
|
|
metadata[:file_path]
|
|
|
|
end
|
|
|
|
|
|
|
|
def line
|
|
|
|
metadata[:line_number]
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
metadata[:full_description]
|
|
|
|
end
|
|
|
|
|
|
|
|
def attempts
|
2021-02-23 04:10:45 -05:00
|
|
|
rspec_example.respond_to?(:attempts) ? rspec_example.attempts : 1
|
2017-07-19 13:51:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :rspec_example
|
|
|
|
|
|
|
|
def metadata
|
|
|
|
rspec_example.metadata
|
|
|
|
end
|
|
|
|
|
|
|
|
def execution_result
|
|
|
|
rspec_example.execution_result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|