Class: Specify

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_html_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(examples) ⇒ Specify

Returns a new instance of Specify.



114
115
116
# File 'lib/rspec_html_formatter.rb', line 114

def initialize(examples)
  @examples = examples
end

Instance Method Details

#processObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rspec_html_formatter.rb', line 118

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