class Example
Attributes
duration[R]
exception[R]
file_path[R]
metadata[R]
run_time[R]
screen_grab[R]
spec[R]
status[R]
video_record[R]
Public Class Methods
load_spec_comments!(examples)
click to toggle source
# File lib/specify_html_reporter/example.rb, line 66 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 |example, next_ex| determine_lexical_next(example, next_ex) process_spec_lines(example, next_ex, lines) end end end
new(example)
click to toggle source
# File lib/specify_html_reporter/example.rb, line 11 def initialize(example) @spec = nil @example = example setup_execution_result setup_example_data setup_metadata setup_exception end
Private Class Methods
determine_lexical_next(example, next_ex)
click to toggle source
# File lib/specify_html_reporter/example.rb, line 82 def determine_lexical_next(example, next_ex) @lexical = next_ex && next_ex.file_path == example.file_path && next_ex.metadata[:line_number] > example.metadata[:line_number] end
process_spec_lines(example, next_ex, lines)
click to toggle source
# File lib/specify_html_reporter/example.rb, line 88 def process_spec_lines(example, next_ex, lines) start_line = example.metadata[:line_number] - 1 next_start = (@lexical ? next_ex.metadata[:line_number] : lines.size) - 1 spec_lines = lines[start_line...next_start].select { |l| l.match(/#->/) } example.create_spec_line(spec_lines.join) unless spec_lines.empty? end
Public Instance Methods
comment()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 52 def comment ERB::Util.html_escape(@comment) end
comment?()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 56 def comment? !@comment.nil? end
create_spec_line(spec_text)
click to toggle source
# File lib/specify_html_reporter/example.rb, line 60 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
# File lib/specify_html_reporter/example.rb, line 30 def example_title full_title = @example_group.to_s.split('::') - %w[RSpec ExampleGroups] full_title.push @description full_title.join(' → ') end
exception?()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 36 def exception? !@exception.problem.nil? end
result_type(prefix = 'label-')
click to toggle source
# File lib/specify_html_reporter/example.rb, line 20 def result_type(prefix = 'label-') class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" } class_map[@status.to_sym] end
screen_grab?()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 44 def screen_grab? !@screen_grab.nil? && !@screen_grab.empty? end
spec?()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 40 def spec? !@spec.nil? end
video_record?()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 48 def video_record? !@video_record.nil? end
Private Instance Methods
setup_example_data()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 103 def setup_example_data @example_group = @example.example_group.to_s @description = @example.description @full_description = @example.full_description @metadata = @example.metadata end
setup_exception()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 117 def setup_exception @exception = Problem.new(@example, @file_path) end
setup_execution_result()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 96 def setup_execution_result @execution_result = @example.execution_result @run_time = @execution_result.run_time.round(5) @status = @execution_result.status.to_s @duration = @execution_result.run_time.to_s(:rounded, precision: 5) end
setup_metadata()
click to toggle source
# File lib/specify_html_reporter/example.rb, line 110 def setup_metadata @file_path = @metadata[:file_path] @comment = @metadata[:comment] @screen_grab = @metadata[:screen_grab] @video_record = @metadata[:video_record] end