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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rspec_html_reporter.rb', line 103 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 = example. @file_path = [:file_path] @exception = Oopsy.new(example, @file_path) @spec = nil @screenshots = [:screenshots] @screenrecord = [:screenrecord] @failed_screenshot = [:failed_screenshot] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def description @description end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def duration @duration end |
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def example_group @example_group end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def exception @exception end |
#failed_screenshot ⇒ Object (readonly)
Returns the value of attribute failed_screenshot.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def failed_screenshot @failed_screenshot end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def file_path @file_path end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def full_description @full_description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def run_time @run_time end |
#screenrecord ⇒ Object (readonly)
Returns the value of attribute screenrecord.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def screenrecord @screenrecord end |
#screenshots ⇒ Object (readonly)
Returns the value of attribute screenshots.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def screenshots @screenshots end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def spec @spec end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
101 102 103 |
# File 'lib/rspec_html_reporter.rb', line 101 def status @status end |
Class Method Details
.load_spec_comments!(examples) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rspec_html_reporter.rb', line 85 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
120 121 122 123 124 125 |
# File 'lib/rspec_html_reporter.rb', line 120 def example_title title_arr = @example_group.to_s.split('::') - ['RSpec', 'ExampleGroups'] title_arr.push @description title_arr.join(' → ') end |
#has_exception? ⇒ Boolean
127 128 129 |
# File 'lib/rspec_html_reporter.rb', line 127 def has_exception? !@exception.klass.nil? end |
#has_failed_screenshot? ⇒ Boolean
143 144 145 |
# File 'lib/rspec_html_reporter.rb', line 143 def has_failed_screenshot? !@failed_screenshot.nil? end |
#has_screenrecord? ⇒ Boolean
139 140 141 |
# File 'lib/rspec_html_reporter.rb', line 139 def has_screenrecord? !@screenrecord.nil? end |
#has_screenshots? ⇒ Boolean
135 136 137 |
# File 'lib/rspec_html_reporter.rb', line 135 def has_screenshots? !@screenshots.nil? && !@screenshots.empty? end |
#has_spec? ⇒ Boolean
131 132 133 |
# File 'lib/rspec_html_reporter.rb', line 131 def has_spec? !@spec.nil? end |
#klass(prefix = 'label-') ⇒ Object
153 154 155 156 |
# File 'lib/rspec_html_reporter.rb', line 153 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
147 148 149 150 151 |
# File 'lib/rspec_html_reporter.rb', line 147 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 |