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. - #lang ⇒ Object
-
#parse(step_mother, options) ⇒ Object
Parses a file and returns a Cucumber::Ast If
options
contains tags, 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 ba a path or a path:line1:line2 etc. If source
is passed, uri
is ignored.
11 12 13 14 15 16 17 18 19 |
# File 'lib/cucumber/feature_file.rb', line 11 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
#lang ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/cucumber/feature_file.rb', line 45 def lang line_one = source.split(/\n/)[0] if line_one =~ LANGUAGE_PATTERN $1.strip else nil end end |
#parse(step_mother, options) ⇒ Object
Parses a file and returns a Cucumber::Ast If options
contains tags, the result will be filtered.
24 25 26 27 28 |
# File 'lib/cucumber/feature_file.rb', line 24 def parse(step_mother, ) filter = Filter.new(@lines, ) language = Parser::NaturalLanguage.get(step_mother, (lang || 'en')) language.parse(source, @path, filter) end |
#source ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cucumber/feature_file.rb', line 30 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 |