Module: Cucumber::Core::Test::Location

Defined in:
lib/cucumber/core/test/location.rb

Defined Under Namespace

Classes: Lines, Precise, Wildcard

Class Method Summary collapse

Class Method Details

.from_file_colon_line(file_colon_line) ⇒ Object



15
16
17
18
# File 'lib/cucumber/core/test/location.rb', line 15

def self.from_file_colon_line(file_colon_line)
  file, raw_line = file_colon_line.match(/(.*):(\d+)/)[1..2]
  from_source_location(file, raw_line.to_i)
end

.from_source_location(file, line) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cucumber/core/test/location.rb', line 20

def self.from_source_location(file, line)
  file = File.expand_path(file)
  pwd = File.expand_path(Dir.pwd)
  pwd.force_encoding(file.encoding)
  if file.index(pwd)
    file = file[pwd.length + 1..-1]
  elsif file =~ /.*\/gems\/(.*\.rb)$/
    file = $1
  end
  new(file, line)
end

.new(file, raw_lines = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cucumber/core/test/location.rb', line 32

def self.new(file, raw_lines=nil)
  file || raise(ArgumentError, 'file is mandatory')
  if raw_lines
    Precise.new(file, Lines.new(raw_lines))
  else
    Wildcard.new(file)
  end
end

.of_caller(additional_depth = 0) ⇒ Object



11
12
13
# File 'lib/cucumber/core/test/location.rb', line 11

def self.of_caller(additional_depth = 0)
  from_file_colon_line(*caller[1 + additional_depth])
end