Class: Cucumber::FeatureFile
Constant Summary collapse
- FILE_COLON_LINE_PATTERN =
:nodoc:
/^([\w\W]*?):([\d:]+)$/
- LANGUAGE_PATTERN =
:nodoc:
/language:\s*(.*)/
Instance Method Summary collapse
-
#initialize(uri, source = nil) ⇒ FeatureFile
constructor
The
uri
argument is the location of the source. -
#parse(configuration_filters, tag_counts) ⇒ Object
Parses a file and returns a Cucumber::Ast If
configuration_filters
contains any filters, the result will be filtered. - #source ⇒ Object
Constructor Details
#initialize(uri, source = nil) ⇒ FeatureFile
The uri
argument is the location of the source. It can be a path or a path:line1:line2 etc. If source
is passed, uri
is ignored.
13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Method Details
#parse(configuration_filters, tag_counts) ⇒ Object
Parses a file and returns a Cucumber::Ast If configuration_filters
contains any filters, the result will be filtered.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cucumber/feature_file.rb', line 26 def parse(configuration_filters, tag_counts) filters = @lines || configuration_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::Lexer::LexingError, Gherkin::Parser::ParseError => e e..insert(0, "#{@path}: ") raise e end end |
#source ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cucumber/feature_file.rb', line 47 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.(@path) e. << "\nCouldn't open #{p}" raise e end end end |