Class: Example

Inherits:
Object
  • Object
show all
Defined in:
lib/specify_html_reporter/example.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Example

Returns a new instance of Example.



11
12
13
14
15
16
17
18
# File 'lib/specify_html_reporter/example.rb', line 11

def initialize(example)
  @spec = nil
  @example = example
  setup_execution_result
  setup_example_data
  
  setup_exception
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def duration
  @duration
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def exception
  @exception
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def file_path
  @file_path
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def 
  @metadata
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def run_time
  @run_time
end

#screen_grabObject (readonly)

Returns the value of attribute screen_grab.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def screen_grab
  @screen_grab
end

#specObject (readonly)

Returns the value of attribute spec.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def spec
  @spec
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def status
  @status
end

#video_recordObject (readonly)

Returns the value of attribute video_record.



8
9
10
# File 'lib/specify_html_reporter/example.rb', line 8

def video_record
  @video_record
end

Class Method Details

.load_spec_comments!(examples) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# 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

Instance Method Details

#commentObject



52
53
54
# File 'lib/specify_html_reporter/example.rb', line 52

def comment
  ERB::Util.html_escape(@comment)
end

#comment?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/specify_html_reporter/example.rb', line 56

def comment?
  !@comment.nil?
end

#create_spec_line(spec_text) ⇒ Object



60
61
62
63
64
# 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_titleObject



30
31
32
33
34
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/specify_html_reporter/example.rb', line 36

def exception?
  !@exception.problem.nil?
end

#result_type(prefix = 'label-') ⇒ Object



20
21
22
23
24
25
26
27
28
# 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?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/specify_html_reporter/example.rb', line 44

def screen_grab?
  !@screen_grab.nil? && !@screen_grab.empty?
end

#spec?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/specify_html_reporter/example.rb', line 40

def spec?
  !@spec.nil?
end

#video_record?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/specify_html_reporter/example.rb', line 48

def video_record?
  !@video_record.nil?
end