Class: Example
- Inherits:
-
Object
- Object
- Example
- Defined in:
- lib/rspec_pretty_html_reporter/example.rb
Overview
Processes the array of example information for all of the example group that has been run
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 = 'badge-') ⇒ Object
- #set_spec(spec_text) ⇒ Object
Constructor Details
#initialize(example) ⇒ Example
Returns a new instance of Example.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 24 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_fs(: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.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def description @description end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def duration @duration end |
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def example_group @example_group end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def exception @exception end |
#failed_screenshot ⇒ Object (readonly)
Returns the value of attribute failed_screenshot.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def failed_screenshot @failed_screenshot end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def file_path @file_path end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def full_description @full_description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def @metadata end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def run_time @run_time end |
#screenrecord ⇒ Object (readonly)
Returns the value of attribute screenrecord.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def screenrecord @screenrecord end |
#screenshots ⇒ Object (readonly)
Returns the value of attribute screenshots.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def screenshots @screenshots end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def spec @spec end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
21 22 23 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 21 def status @status end |
Class Method Details
.load_spec_comments!(examples) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 5 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
41 42 43 44 45 46 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 41 def example_title title_arr = @example_group.to_s.split('::') - %w[RSpec ExampleGroups] title_arr.push @description title_arr.join(' → ') end |
#has_exception? ⇒ Boolean
48 49 50 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 48 def has_exception? !@exception.klass.nil? end |
#has_failed_screenshot? ⇒ Boolean
64 65 66 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 64 def has_failed_screenshot? !@failed_screenshot.nil? end |
#has_screenrecord? ⇒ Boolean
60 61 62 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 60 def has_screenrecord? !@screenrecord.nil? end |
#has_screenshots? ⇒ Boolean
56 57 58 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 56 def has_screenshots? !@screenshots.nil? && !@screenshots.empty? end |
#has_spec? ⇒ Boolean
52 53 54 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 52 def has_spec? !@spec.nil? end |
#klass(prefix = 'badge-') ⇒ Object
74 75 76 77 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 74 def klass(prefix = 'badge-') class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" } class_map[@status.to_sym] end |
#set_spec(spec_text) ⇒ Object
68 69 70 71 72 |
# File 'lib/rspec_pretty_html_reporter/example.rb', line 68 def set_spec(spec_text) formatter = Rouge::Formatters::HTML.new lexer = Rouge::Lexers::Gherkin.new @spec = %(<div class="highlight"><pre class="highlight"><code>#{formatter.format(lexer.lex(spec_text.gsub('#->', '')))}</code></pre></div>) end |