Reputation: 61
I don't quite understand why my test isn't running. It works if I include it in the calc.rb file. However, when I split the test up and try and run it in the test_calc.rb the file does not run. And I get the following error:
/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from test_fall.rb:6:in `<class:TestAdd>'
from test_fall.rb:4:in `<main>'
I don't quite understand why it's looking in the 2.1.4 directory for the file.
calc.rb
class Calc
def add(a, b)
a + b
end
end
test_calc.rb
require 'calc.rb'
require 'minitest/autorun'
class TestAdd < Minitest::Test
def test_add
calc = Calc.new
expected = calc.add 3,2
assert_equal expected, 5
end
def test_add_bigint
calc = Calc.new
val = calc.add 10000000, 10000000
assert_equal val, 20000000
end
end
Upvotes: 1
Views: 45
Reputation: 219
Try using require_relative
. This is most likely related to the directory structure where your code library is and where your tests/specs are located. I'm pretty sure ruby first looks in the same directory and then goes on to the bins.
If you have these in separate folders, try adding them to the same folder and running tests. If you'd like more information on require_relative you can find it here
Let us know if it works. If not, show us your directory tree and where the files are located.
Upvotes: 3