summaryrefslogtreecommitdiff
path: root/lib/rspec_flaky/example.rb
diff options
context:
space:
mode:
authorMarcia Ramos <virtua.creative@gmail.com>2017-08-15 11:20:11 -0300
committerMarcia Ramos <virtua.creative@gmail.com>2017-08-15 11:20:11 -0300
commit35c9a75eff464ff7bb0e58c67488a6fa1bdebaaa (patch)
treeb78097fd10cad31f45b8b6613d45960f2872802c /lib/rspec_flaky/example.rb
parent0112d13314e1aea350c7dacc02c0f1c527566809 (diff)
parentfe09c25d68a61c5874e9beb0f018c05a4d789d70 (diff)
downloadgitlab-ce-docs-topic-permissions.tar.gz
Diffstat (limited to 'lib/rspec_flaky/example.rb')
-rw-r--r--lib/rspec_flaky/example.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/rspec_flaky/example.rb b/lib/rspec_flaky/example.rb
new file mode 100644
index 00000000000..b6e790cbbab
--- /dev/null
+++ b/lib/rspec_flaky/example.rb
@@ -0,0 +1,46 @@
+module RspecFlaky
+ # This is a wrapper class for RSpec::Core::Example
+ class Example
+ delegate :status, :exception, to: :execution_result
+
+ def initialize(rspec_example)
+ @rspec_example = rspec_example.try(:example) || rspec_example
+ 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
+ rspec_example.try(:attempts) || 1
+ end
+
+ private
+
+ attr_reader :rspec_example
+
+ def metadata
+ rspec_example.metadata
+ end
+
+ def execution_result
+ rspec_example.execution_result
+ end
+ end
+end