Class: RSpec::Lono::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/lono/detector.rb

Instance Method Summary collapse

Instance Method Details

#blueprintObject



3
4
5
6
# File 'lib/rspec/lono/detector.rb', line 3

def blueprint
  md = calling_file.match(%r{/blueprints/(.*)/test/spec/})
  md[1]
end

#calling_fileObject

Automatically discover the blueprint root path

Caller lines are different for OSes:

windows: "C:/Users/user/lono-project/app/blueprints/demo/test/spec/blueprint_spec.rb:12:in `block (2 levels) in <top (required)>'"
linux: "/home/user/lono-project/app/blueprints/demo/test/spec/blueprint_spec.rb:12:in `block (2 levels) in <top (required)>'"


19
20
21
22
23
# File 'lib/rspec/lono/detector.rb', line 19

def calling_file
  caller_line = caller.find { |l| l.include?("_spec.rb") }
  parts = caller_line.split(':')
  caller_line.match(/^[a-zA-Z]:/) ? parts[1] : parts[0]
end

#rootObject



8
9
10
# File 'lib/rspec/lono/detector.rb', line 8

def root
  calling_file.sub(%r{/test/spec/.*}, '') # IE: /home/user/lono-project/app/blueprints/demo
end