Class: Example
- Inherits:
-
Object
- Object
- Example
- Defined in:
- lib/test_spec/rspec/example.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
-
.load_spec_comments!(examples) ⇒ Object
rubocop:disable Metrics/LineLength rubocop:disable Metrics/AbcSize.
Instance Method Summary collapse
- #comment ⇒ Object
- #create_spec_line(spec_text) ⇒ Object
-
#example_title ⇒ Object
rubocop:enable Metrics/AbcSize.
- #has_comment? ⇒ Boolean
- #has_exception? ⇒ Boolean
- #has_failed_screenshot? ⇒ Boolean
- #has_screenrecord? ⇒ Boolean
- #has_screenshots? ⇒ Boolean
- #has_spec? ⇒ Boolean
-
#initialize(example) ⇒ Example
constructor
rubocop:disable Metrics/AbcSize.
- #klass(prefix = 'label-') ⇒ Object
Constructor Details
#initialize(example) ⇒ Example
rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/test_spec/rspec/example.rb', line 9 def initialize(example) @execution_result = example.execution_result @run_time = @execution_result.run_time.round(5) @status = @execution_result.status.to_s @example_group = example.example_group.to_s @description = example.description @full_description = example.full_description @metadata = example. @duration = @execution_result.run_time.to_s(:rounded, precision: 5) @screenrecord = @metadata[:screenrecord] @screenshots = @metadata[:screenshots] @spec = nil @file_path = @metadata[:file_path] @exception = Problem.new(example, @file_path) @failed_screenshot = @metadata[:failed_screenshot] @comment = @metadata[:comment] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def description @description end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def duration @duration end |
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def example_group @example_group end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def exception @exception end |
#failed_screenshot ⇒ Object (readonly)
Returns the value of attribute failed_screenshot.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def failed_screenshot @failed_screenshot end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def file_path @file_path end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def full_description @full_description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def @metadata end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def run_time @run_time end |
#screenrecord ⇒ Object (readonly)
Returns the value of attribute screenrecord.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def screenrecord @screenrecord end |
#screenshots ⇒ Object (readonly)
Returns the value of attribute screenshots.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def screenshots @screenshots end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def spec @spec end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/test_spec/rspec/example.rb', line 4 def status @status end |
Class Method Details
.load_spec_comments!(examples) ⇒ Object
rubocop:disable Metrics/LineLength rubocop:disable Metrics/AbcSize
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/test_spec/rspec/example.rb', line 80 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.create_spec_line(spec_lines.join) unless spec_lines.empty? end end end |
Instance Method Details
#comment ⇒ Object
34 35 36 |
# File 'lib/test_spec/rspec/example.rb', line 34 def comment ERB::Util.html_escape(@comment) end |
#create_spec_line(spec_text) ⇒ Object
72 73 74 75 76 |
# File 'lib/test_spec/rspec/example.rb', line 72 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_title ⇒ Object
rubocop:enable Metrics/AbcSize
28 29 30 31 32 |
# File 'lib/test_spec/rspec/example.rb', line 28 def example_title title_arr = @example_group.to_s.split('::') - %w[RSpec ExampleGroups] title_arr.push @description title_arr.join(' → ') end |
#has_comment? ⇒ Boolean
42 43 44 |
# File 'lib/test_spec/rspec/example.rb', line 42 def has_comment? !@comment.nil? end |
#has_exception? ⇒ Boolean
58 59 60 |
# File 'lib/test_spec/rspec/example.rb', line 58 def has_exception? !@exception.klass.nil? end |
#has_failed_screenshot? ⇒ Boolean
54 55 56 |
# File 'lib/test_spec/rspec/example.rb', line 54 def has_failed_screenshot? !@failed_screenshot.nil? end |
#has_screenrecord? ⇒ Boolean
46 47 48 |
# File 'lib/test_spec/rspec/example.rb', line 46 def has_screenrecord? !@screenrecord.nil? end |
#has_screenshots? ⇒ Boolean
50 51 52 |
# File 'lib/test_spec/rspec/example.rb', line 50 def has_screenshots? !@screenshots.nil? && !@screenshots.empty? end |
#has_spec? ⇒ Boolean
38 39 40 |
# File 'lib/test_spec/rspec/example.rb', line 38 def has_spec? !@spec.nil? end |
#klass(prefix = 'label-') ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/test_spec/rspec/example.rb', line 62 def klass(prefix = 'label-') class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" } class_map[@status.to_sym] end |