Class: Cucumber::FeatureFile

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

Constant Summary collapse

FILE_COLON_LINE_PATTERN =

:nodoc:

/^([\w\W]*?):([\d:]+)$/
LANGUAGE_PATTERN =

:nodoc:

/language:\s*(.*)/

Instance Method Summary collapse

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

#langObject



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, options)
  filter = Filter.new(@lines, options)
  language = Parser::NaturalLanguage.get(step_mother, (lang || options[:lang] || 'en'))
  language.parse(source, @path, filter)
end

#sourceObject



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.expand_path(@path)
      e.message << "\nCouldn't open #{p}"
      raise e
    end
  end
end