class Cucumber::FeatureFile
def initialize(uri, source=nil)
The +uri+ argument is the location of the source. It can ba a path
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
def parse(options, tag_counts)
If +options+ contains tags, the result will
Parses a file and returns a Cucumber::Ast
def parse(options, tag_counts) filters = @lines || options.filters builder = Cucumber::Parser::GherkinBuilder.new filter_formatter = filters.empty? ? builder : Gherkin::Formatter::FilterFormatter.new(builder, filters) tag_count_formatter = Gherkin::Formatter::TagCountFormatter.new(filter_formatter, tag_counts) parser = Gherkin::Parser::Parser.new(tag_count_formatter, true, "root", false) begin parser.parse(source, @path, 0) ast = builder.ast return nil if ast.nil? # Filter caused nothing to match ast.language = parser.i18n_language ast.file = @path ast rescue Gherkin::LexingError, Gherkin::Parser::ParseError => e e.message.insert(0, "#{@path}: ") raise e end end
def source
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