I would like test code in the lib directory of Rails. I use RubyTest to work in Sublime Text 2. My library is in lib/my_lib
.
module MyLib
def self.get_zero
0
end
end
My unit test is in test/unit/lib/my_lib
require 'test/unit'
require 'my_lib/my_class_to_test'
module MyLib
class MyClassToTestTest < Test::Unit::TestCase
def test_zero
assert_equal(0, MyLib::get_zero)
end
end
end
Unit tests pass when I run them with the command line:
rake test:units
To save time I can run only my unit test with this command line:
ruby -I"lib" test/unit/lib/my_lib/my_class_to_test_test.rb
I would like use RubyTest with Sublime Text 2 but when I use it (Maj+Ctrl+R) I obtain error :
test/unit/lib/my_lib/my_class_to_test_test.rb:3:in `require': no such file to load -- my_lib/my_class_to_test (LoadError)
from test/unit/lib/my_lib/my_class_to_test_test.rb:3
How RubyTest could load the lib directory in the path ?
The configuration file of RubyTest in Sublime Text 2 is here:
~/.config/sublime-text-2/Packages/RubyTest/RubyTest.sublime-settings
I added lib
to the -I
option in the ruby_unit_exec
like that:
"ruby_unit_exec": "ruby -Ilib:test"`
The problem is fixed.