Class: Example
- Inherits:
-
Object
- Object
- Example
- Defined in:
- lib/rspec_html_reporter.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#example_group ⇒ Object
readonly
Returns the value of attribute example_group.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#failed_screenshot ⇒ Object
readonly
Returns the value of attribute failed_screenshot.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#full_description ⇒ Object
readonly
Returns the value of attribute full_description.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#run_time ⇒ Object
readonly
Returns the value of attribute run_time.
-
#screenrecord ⇒ Object
readonly
Returns the value of attribute screenrecord.
-
#screenshots ⇒ Object
readonly
Returns the value of attribute screenshots.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #example_title ⇒ Object
- #has_exception? ⇒ Boolean
- #has_failed_screenshot? ⇒ Boolean
- #has_screenrecord? ⇒ Boolean
- #has_screenshots? ⇒ Boolean
- #has_spec? ⇒ Boolean
-
#initialize(example) ⇒ Example
constructor
A new instance of Example.
- #klass(prefix = 'label-') ⇒ Object
- #set_spec(spec_text) ⇒ Object
Constructor Details
#initialize(example) ⇒ Example
Returns a new instance of Example.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rspec_html_reporter.rb', line 106 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, @file_path) @spec = nil @screenshots = @metadata[:screenshots] @screenrecord = @metadata[:screenrecord] @failed_screenshot = @metadata[:failed_screenshot] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def description @description end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def duration @duration end |
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def example_group @example_group end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def exception @exception end |
#failed_screenshot ⇒ Object (readonly)
Returns the value of attribute failed_screenshot.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def failed_screenshot @failed_screenshot end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def file_path @file_path end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def full_description @full_description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def @metadata end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def run_time @run_time end |
#screenrecord ⇒ Object (readonly)
Returns the value of attribute screenrecord.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def screenrecord @screenrecord end |
#screenshots ⇒ Object (readonly)
Returns the value of attribute screenshots.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def screenshots @screenshots end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def spec @spec end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
104 105 106 |
# File 'lib/rspec_html_reporter.rb', line 104 def status @status end |
Class Method Details
.load_spec_comments!(examples) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rspec_html_reporter.rb', line 88 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.[:line_number] > ex.[:line_number] start_line_idx = ex.[:line_number] - 1 next_start_idx = (lexically_next ? next_ex.[:line_number] : lines.size) - 1 spec_lines = lines[start_line_idx...next_start_idx].select { |l| l.match(/#->/) } ex.set_spec(spec_lines.join) unless spec_lines.empty? end end end |
Instance Method Details
#example_title ⇒ Object
123 124 125 126 127 128 |
# File 'lib/rspec_html_reporter.rb', line 123 def example_title title_arr = @example_group.to_s.split('::') - ['RSpec', 'ExampleGroups'] title_arr.push @description title_arr.join(' → ') end |
#has_exception? ⇒ Boolean
130 131 132 |
# File 'lib/rspec_html_reporter.rb', line 130 def has_exception? !@exception.klass.nil? end |
#has_failed_screenshot? ⇒ Boolean
146 147 148 |
# File 'lib/rspec_html_reporter.rb', line 146 def has_failed_screenshot? !@failed_screenshot.nil? end |
#has_screenrecord? ⇒ Boolean
142 143 144 |
# File 'lib/rspec_html_reporter.rb', line 142 def has_screenrecord? !@screenrecord.nil? end |
#has_screenshots? ⇒ Boolean
138 139 140 |
# File 'lib/rspec_html_reporter.rb', line 138 def has_screenshots? !@screenshots.nil? && !@screenshots.empty? end |
#has_spec? ⇒ Boolean
134 135 136 |
# File 'lib/rspec_html_reporter.rb', line 134 def has_spec? !@spec.nil? end |
#klass(prefix = 'label-') ⇒ Object
156 157 158 159 |
# File 'lib/rspec_html_reporter.rb', line 156 def klass(prefix='label-') class_map = {passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning"} class_map[@status.to_sym] end |
#set_spec(spec_text) ⇒ Object
150 151 152 153 154 |
# File 'lib/rspec_html_reporter.rb', line 150 def set_spec(spec_text) formatter = Rouge::Formatters::HTML.new(css_class: 'highlight') lexer = Rouge::Lexers::Gherkin.new @spec = formatter.format(lexer.lex(spec_text.gsub('#->', ''))) end |