Sha256: 2a96cf8aed3e3a62330e74539e0cff3143219429d8fc695d2f2e6e8f45cdce2f

Contents?: true

Size: 1.44 KB

Versions: 41

Compression:

Stored size: 1.44 KB

Contents

require 'cucumber/parser/natural_language'
require 'cucumber/filter'

module Cucumber
  class FeatureFile
    FILE_COLON_LINE_PATTERN = /^([\w\W]*?):([\d:]+)$/ #:nodoc:
    LANGUAGE_PATTERN = /language:\s*(.*)/ #:nodoc:

    # 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.
    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
    
    # Parses a file and returns a Cucumber::Ast
    # If +options+ contains tags, the result will
    # be filtered.
    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
    
    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
    
    def lang
      line_one = source.split(/\n/)[0]
      if line_one =~ LANGUAGE_PATTERN
        $1.strip
      else
        nil
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 8 rubygems

Version Path
aslakhellesoy-cucumber-0.3.100 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.101.2 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.101 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.102.1 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.102.2 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.102 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.103 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.104 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.97 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.98 lib/cucumber/feature_file.rb
aslakhellesoy-cucumber-0.3.99 lib/cucumber/feature_file.rb
dwaite-cucumber-0.3.101 lib/cucumber/feature_file.rb
engineyard-cucumber-0.3.101 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.100 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.102 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.103 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.97 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.98 lib/cucumber/feature_file.rb
kosmas58-cucumber-0.3.99 lib/cucumber/feature_file.rb
cucumber-0.4.5.rc2 lib/cucumber/feature_file.rb