Reputation: 1304
I'm want to automate testing with rake. When I run this from the command prompt, in the home directory, my tests run fine.
ruby -I lib/radar_mon/ tests/radar_mon/test_geoname.rb
my Rakefile looks like this:
task default: %w[test]
task :test do
ruby "tests/radar_mon/test_geoname.rb"
end
my test file test_geoname.rb looks like this
require 'test/unit'
require 'geoname'
class TestGeoname < Test::Unit::TestCase
def test_first
g = Geoname.new( [0.0,0.0] )
assert_equal( [0.0,0.0], g.location)
end
end
Library structure is like this
home/lib/radar_mon/geoname.rb
home/tests/radar_mon/test_geoname.rb
home/Rakefile
How can I configure my rake file to run the test? I'm not supposed to change the require statement in the test file.
/home/pi/.rvm/rubies/ruby-2.2.10/bin/ruby tests/radar_mon/test_geoname.rb
tests/radar_mon/test_geoname.rb:2:in `require_relative': cannot load such file -- /home/pi/Documents/HurricaneTracker/tests/radar_mon/geoname (LoadError)
from tests/radar_mon/test_geoname.rb:2:in `<main>'
rake aborted!
Not sure if it matters but I'm using rvm.
Upvotes: 0
Views: 425
Reputation: 11216
What about trying to add something like this to the top of your Rakefile, you might need to modify this to only require files needed by your rake task.
Dir[File.join(__dir__, "/**/*.rb")].each do |file|
require file
end
More specifically for your case this would work:
my_files = FileList['home/lib/radar_mon/*.rb', 'home/tests/radar_mon.*rb']
my_files.each do |file|
require file
end
task default: %w[test]
task :test do
ruby "tests/radar_mon/test_geoname.rb"
end
This works because Rake is handling the requires in this case recursively. FileList
is provided by rake
.
For more info you might wanna refer to the rake gem documentation and perhaps http://www.virtuouscode.com/2014/04/24/rake-part-4-pathmap/
Upvotes: 1