Class: Example

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Example

Returns a new instance of Example.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rspec_html_formatter.rb', line 81

def initialize(example)
  @example_group = example.example_group.to_s
  @description = example.description
  @full_description = example.full_description
  @execution_result = example.execution_result
  @run_time = (@execution_result.run_time).round(5)
  @duration = @execution_result.run_time.to_s(:rounded, precision: 5)
  @status = @execution_result.status.to_s
  @metadata = example.
  @file_path = @metadata[:file_path]
  @exception = Oopsy.new(example.exception, @file_path)
  @spec = nil
  @screenshots = @metadata[:screenshots]
  @screenrecord = @metadata[:screenrecord]
  @failed_screenshot = @metadata[:failed_screenshot]
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def description
  @description
end

#durationObject (readonly)

Returns the value of attribute duration.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def duration
  @duration
end

#example_groupObject (readonly)

Returns the value of attribute example_group.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def example_group
  @example_group
end

#exceptionObject (readonly)

Returns the value of attribute exception.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def exception
  @exception
end

#failed_screenshotObject (readonly)

Returns the value of attribute failed_screenshot.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def failed_screenshot
  @failed_screenshot
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def file_path
  @file_path
end

#full_descriptionObject (readonly)

Returns the value of attribute full_description.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def full_description
  @full_description
end

#metadataObject (readonly)

Returns the value of attribute metadata.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def 
  @metadata
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def run_time
  @run_time
end

#screenrecordObject (readonly)

Returns the value of attribute screenrecord.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def screenrecord
  @screenrecord
end

#screenshotsObject (readonly)

Returns the value of attribute screenshots.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def screenshots
  @screenshots
end

#specObject (readonly)

Returns the value of attribute spec.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def spec
  @spec
end

#statusObject (readonly)

Returns the value of attribute status.



79
80
81
# File 'lib/rspec_html_formatter.rb', line 79

def status
  @status
end

Instance Method Details

#example_titleObject



98
99
100
101
102
103
# File 'lib/rspec_html_formatter.rb', line 98

def example_title
  title_arr = @example_group.to_s.split('::') - ['RSpec', 'ExampleGroups']
  title_arr.push @description

  title_arr.join('')
end

#has_exception?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/rspec_html_formatter.rb', line 105

def has_exception?
  !@exception.klass.nil?
end

#has_failed_screenshot?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/rspec_html_formatter.rb', line 121

def has_failed_screenshot?
  !@failed_screenshot.nil?
end

#has_screenrecord?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/rspec_html_formatter.rb', line 117

def has_screenrecord?
  !@screenrecord.nil?
end

#has_screenshots?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/rspec_html_formatter.rb', line 113

def has_screenshots?
  !@screenshots.nil? && !@screenshots.empty?
end

#has_spec?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/rspec_html_formatter.rb', line 109

def has_spec?
  !@spec.nil?
end

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



129
130
131
132
# File 'lib/rspec_html_formatter.rb', line 129

def klass(prefix='label-')
  class_map = {passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning"}
  class_map[@status.to_sym]
end

#set_spec(spec) ⇒ Object



125
126
127
# File 'lib/rspec_html_formatter.rb', line 125

def set_spec(spec)
  @spec = spec
end