Class: Micron::Runner::Shim

Inherits:
Object
  • Object
show all
Defined in:
lib/micron/runner/shim.rb

Class Method Summary collapse

Class Method Details

.cleanup!Object

Clean up any existing shim dirs. This should be called only when the master process exists (i.e. Micron::App)



44
45
46
47
48
49
# File 'lib/micron/runner/shim.rb', line 44

def self.cleanup!
  # return
  Dir.glob(File.join(Dir.tmpdir, "micron-shim-*")).each do |d|
    FileUtils.rm_rf(d)
  end
end

.setupObject

Create a temp shim path



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/micron/runner/shim.rb', line 9

def self.setup

  ruby_path = `which ruby`.strip
  shim = <<-EOF
#!#{ruby_path}

if ENV["BUNDLE_GEMFILE"] then
  require "bundler"
  Bundler.setup(:default, :development, :test)
end

require "easycov"

EasyCov.path = ENV["EASYCOV_PATH"]
EasyCov.filters << EasyCov::IGNORE_GEMS << EasyCov::IGNORE_STDLIB
EasyCov.start
EasyCov.install_exit_hook()

script = ARGV.shift
$0 = script
require script
EOF

  @shim_dir = Dir.mktmpdir("micron-shim-")
  file = File.join(@shim_dir, "ruby")
  File.open(file, 'w') do |f|
    f.write(shim)
  end
  File.chmod(0777, file)
  EasyCov::Filters.stdlib_paths # make sure this gets cached in env

end

.wrap(&block) ⇒ Object

Wrap the given call with our shim PATH. Any calls to ruby will be redirected to our script to enable coverage collection.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/micron/runner/shim.rb', line 53

def self.wrap(&block)
  # enable shim
  ENV["EASYCOV_PATH"] = EasyCov.path
  old_path = ENV["PATH"]
  ENV["PATH"] = "#{@shim_dir}:#{old_path}"

  # call orig method
  block.call()

  # disable shim
  ENV["PATH"] = old_path
end