Class: Specify
- Inherits:
-
Object
- Object
- Specify
- Defined in:
- lib/rspec_html_formatter.rb
Instance Method Summary collapse
-
#initialize(examples) ⇒ Specify
constructor
A new instance of Specify.
- #process ⇒ Object
Constructor Details
#initialize(examples) ⇒ Specify
Returns a new instance of Specify.
90 91 92 |
# File 'lib/rspec_html_formatter.rb', line 90 def initialize(examples) @examples = examples end |
Instance Method Details
#process ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rspec_html_formatter.rb', line 94 def process lines = File.readlines(@examples.first.file_path) @examples.each_with_index do |e, i| start_line = e.[:line_number] end_line = @examples[i+1].nil? ? lines.size : @examples[i+1].[:line_number] - 1 code_block = lines[start_line..end_line] spec = code_block.select { |l| l.match(/#->/) }.join('') if !spec.split.empty? formatter = Rouge::Formatters::HTML.new(css_class: 'highlight') lexer = Rouge::Lexers::Gherkin.new formatted_spec = formatter.format(lexer.lex(spec.gsub('#->', ''))) e.set_spec(formatted_spec) end end @examples end |