What is the correct way of getting this to work?
This is the essence of my problem. I am not clear on what "You will need to run SimpleCov inside your spawned Aruba subprocesses" means from a coding standpoint. Must I include the SimpleCove startup at the top of my production scripts? Where does the invocation go?
We run these ruby programs as batch jobs using a bin/filename stub that looks like this:
#!/usr/bin/env ruby
require 'bundler/setup'
Bundler.require
# Executable for fetching Forex rate changes.
# invoke with: HLL_DB_ENV=production bin/hll_th_forex_rss_fetch
#
# 'Pathname' allows us to eliminate the ../../ construction from
# absolute file paths. It makes reading stack traces a little
# easier.
require 'pathname'
my_dir = Pathname.new(
File.join( File.dirname(
__FILE__ ), '../', 'lib/' ) ).realpath.to_s + '/'
# This loads in the actual program classes and modules for this script
# With Ruby-1.9+ we could use require_relative instead.
require my_dir + File.basename( __FILE__ )
# This invokes the program passing in the argument list from the
# command line.
HllThForexRssFetch::Main.new( ARGV ).execute
Where do I put the SimpleCov invocation? In the bin/file? Before or after the Bundler call? Somewhere else? Do I modify Aruba? Where?
Getting some specific data on this has been like trying to push on a blob of mercury. Every push simply creates more blobs.
#!/usr/bin/env ruby
require 'bundler/setup'
Bundler.require
if ENV['ENV'] == 'test'
require 'simplecov'
SimpleCov.start do
add_filter "/features/"
add_filter "/libexec"
add_filter "/lib/hll_active_record/"
add_filter "/test/"
add_filter "/tmp/"
command_name "this script name"
end
end
. . .
But what I get is:
Coverage report generated for this script name to /home/byrnejb/Projects/Software/theHeart/code/hll_th_forex_rss/tmp/aruba/coverage. 0.0 / 0.0 LOC (100.0%) covered.
>
> Coverage report generated for this script name to /home/byrnejb/Projects/Software/theHeart/code/hll_th_forex_rss/tmp/aruba/coverage. 0.0 / 0.0 LOC (100.0%) covered.
I discovered the problem in the above report: -> /tmp/aruba/coverage.
The root directory for the SimpleCov was incorrect as it was being inferred from the run conditions. Aruba moves things into a tmp directory for testing. I did this to fix the problem:
. . .
require 'pathname'
root_dir = Pathname.new(
File.join( File.dirname(
__FILE__ ), '../' ) ).realpath.to_s + '/'
lib_dir = root_dir + "lib/"
script_name = File.basename( __FILE__ ).to_s
# SimpleCov code coverage reporting
if ENV['ENV'] == 'test'
run_name = script_name + "-" + Time.now.strftime( "%Y%m%d%H%M%S%L" )
require 'simplecov'
SimpleCov.start do
add_filter "/features/"
add_filter "/libexec"
add_filter "/lib/hll_active_record/"
add_filter "/test/"
add_filter "/tmp/"
command_name run_name
root root_dir
end
end
# This loads in the actual program classes and modules for this script
# With Ruby-1.9+ we could use require_relative instead.
require lib_dir + script_name
# This invokes the program passing in the argument list from the
# command line.
HllThForexRssFetch::Main.new( ARGV ).execute
Which now appears to give the desired results.