Parent

Methods

Class/Module Index [+]

Quicksearch

Cucumber::FeatureFile

Constants

CO

Special PML markup that we want to filter out.

C_CALLOUT

Public Class Methods

new(uri, source=nil) click to toggle source

The uri argument is the location of the source. It can ba a path or a path:line1:line2 etc. If source is passed, uri is ignored.

# File lib/cucumber/feature_file.rb, line 13
def initialize(uri, source=nil)
  @source = source
  _, @path, @lines = *FILE_COLON_LINE_PATTERN.match(uri)
  if @path
    @lines = @lines.split(':').map { |line| line.to_i }
  else
    @path = uri
  end
end

Public Instance Methods

parse(step_mother, options) click to toggle source

Parses a file and returns a Cucumber::Ast If options contains tags, the result will be filtered.

# File lib/cucumber/feature_file.rb, line 26
def parse(step_mother, options)
  filters = @lines || options.filters

  builder         = Cucumber::Parser::GherkinBuilder.new
  filter_listener = Gherkin::Parser::FilterListener.new(builder, filters)
  parser          = Gherkin::Parser::Parser.new(filter_listener, true, "root")
  lexer           = Gherkin::I18nLexer.new(parser, false)

  begin
    s = ENV['FILTER_PML_CALLOUT'] ? source.gsub(C_CALLOUT, '') : source
    lexer.scan(s)
    ast = builder.ast
    return nil if ast.nil? # Filter caused nothing to match
    ast.language = lexer.i18n_language
    ast.file = @path
    ast
  rescue Gherkin::LexingError, Gherkin::Parser::ParseError => e
    e.message.insert(0, "#{@path}: ")
    raise e
  end
end
source() click to toggle source
# File lib/cucumber/feature_file.rb, line 48
def source
  @source ||= if @path =~ /^http/
    require 'open-uri'
    open(@path).read
  else
    begin
      File.open(@path, Cucumber.file_mode('r')).read 
    rescue Errno::EACCES => e
      p = File.expand_path(@path)
      e.message << "\nCouldn't open #{p}"
      raise e
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.