class Example
Attributes
description[R]
duration[R]
example_group[R]
exception[R]
failed_screenshot[R]
file_path[R]
full_description[R]
metadata[R]
run_time[R]
screenrecord[R]
screenshots[R]
spec[R]
status[R]
Public Class Methods
load_spec_comments!(examples)
click to toggle source
rubocop:disable Metrics/LineLength rubocop:disable Metrics/AbcSize
# File lib/test_spec/rspec/example.rb, line 80 def self.load_spec_comments!(examples) examples.group_by(&:file_path).each do |file_path, file_examples| lines = File.readlines(file_path) file_examples.zip(file_examples.rotate).each do |ex, next_ex| lexically_next = next_ex && next_ex.file_path == ex.file_path && next_ex.metadata[:line_number] > ex.metadata[:line_number] start_line_idx = ex.metadata[:line_number] - 1 next_start_idx = (lexically_next ? next_ex.metadata[:line_number] : lines.size) - 1 spec_lines = lines[start_line_idx...next_start_idx].select { |l| l.match(/#->/) } ex.create_spec_line(spec_lines.join) unless spec_lines.empty? end end end
new(example)
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/test_spec/rspec/example.rb, line 9 def initialize(example) @execution_result = example.execution_result @run_time = @execution_result.run_time.round(5) @status = @execution_result.status.to_s @example_group = example.example_group.to_s @description = example.description @full_description = example.full_description @metadata = example.metadata @duration = @execution_result.run_time.to_s(:rounded, precision: 5) @screenrecord = @metadata[:screenrecord] @screenshots = @metadata[:screenshots] @spec = nil @file_path = @metadata[:file_path] @exception = Problem.new(example, @file_path) @failed_screenshot = @metadata[:failed_screenshot] @comment = @metadata[:comment] end
Public Instance Methods
comment()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 34 def comment ERB::Util.html_escape(@comment) end
create_spec_line(spec_text)
click to toggle source
# File lib/test_spec/rspec/example.rb, line 72 def create_spec_line(spec_text) formatter = Rouge::Formatters::HTML.new(css_class: 'highlight') lexer = Rouge::Lexers::Gherkin.new @spec = formatter.format(lexer.lex(spec_text.gsub('#->', ''))) end
example_title()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/test_spec/rspec/example.rb, line 28 def example_title title_arr = @example_group.to_s.split('::') - %w[RSpec ExampleGroups] title_arr.push @description title_arr.join(' → ') end
has_comment?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 42 def has_comment? !@comment.nil? end
has_exception?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 58 def has_exception? !@exception.klass.nil? end
has_failed_screenshot?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 54 def has_failed_screenshot? !@failed_screenshot.nil? end
has_screenrecord?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 46 def has_screenrecord? !@screenrecord.nil? end
has_screenshots?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 50 def has_screenshots? !@screenshots.nil? && !@screenshots.empty? end
has_spec?()
click to toggle source
# File lib/test_spec/rspec/example.rb, line 38 def has_spec? !@spec.nil? end
klass(prefix = 'label-')
click to toggle source
# File lib/test_spec/rspec/example.rb, line 62 def klass(prefix = 'label-') class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" } class_map[@status.to_sym] end