For a test in say test/gamemodel, I need to require something like ../../lib/gamemodel/<file>
But when running the same test from some test_all.rb in /test, the correct require is of course ../lib/gamemodel/<file>
(The natural way would have been to simply write require <file>)
It is possible to fix this problem by appending to the load path, but this means rows of duplicate code in every test file.
The problem naturally extends to the lib where you also have to decide where the code supposedly is run from.
Any suggestions on neat ways of solving this problem or are there perhaps packages available to make this work automatically?
For a test in say test/gamemodel, I need to require something
like ../../lib/gamemodel/<file>
But when running the same test from some test_all.rb in /test, the
correct require is of course ../lib/gamemodel/<file>
(The natural way would have been to simply write require <file>)
It is possible to fix this problem by appending to the load path, but
this means rows of duplicate code in every test file.
The problem naturally extends to the lib where you also have to decide
where the code supposedly is run from.
Any suggestions on neat ways of solving this problem or are there
perhaps packages available to make this work automatically?
For a test in say test/gamemodel, I need to require something like ../../lib/gamemodel/<file>
But when running the same test from some test_all.rb in /test, the correct require is of course ../lib/gamemodel/<file>
(The natural way would have been to simply write require <file>)
It is possible to fix this problem by appending to the load path, but this means rows of duplicate code in every test file.
The problem naturally extends to the lib where you also have to decide where the code supposedly is run from.
Any suggestions on neat ways of solving this problem or are there perhaps packages available to make this work automatically?
> When testing your lib you should only need to add lib/ to the load
> path once. For instance you might do:
> ruby -Ilib test/sometest.rb
Yes, but if the test is in
test/client/tc_connect.rb
then I might need to require
test/test_common.rb
You can add test/ to the load path as well if you need too.
lib/client/connect.rb
This should always be:
require 'client/connect'
Again I need to add these libs differently depending on where I start
my test.
Easiest is to always start from your projects root. Using Rake, for
instance, makes that automatic. But as an example of manually running
a test from within the test location:
$ cd test/client
$ ruby -I../../lib;../../test tc_connect.rb
T.
···
On Apr 22, 7:55 am, Christoffer Lernö <le...@dragonascendant.com> wrote: