Hi:
I have been writing unit tests lately and
I have set up my local directory structure
to be parallel to what the install directory
structure is. This way, I can test new code
while old code is still installed and available
for people to execute.
For example, my test_all.rb starts like this:
$:.unshift("../lib")
require 'tc_myclass'
And, away it goes.
Now, I have moved on to integration testing
and am testing ruby applications. The problem
is that when I execute the system call
to run the integration test, I lose the $:.unshift
results.
In other words
$:.unshift("../lib")
system("myapp")
does not work since $: will not have “…/lib”.
I have tried the following:
system("ruby -r ../lib myapp")
but get the error:
No such file to load – …/lib (LoadError)
I think this should be trivial to solve, but right
now I’m not having any luck. Can anyone suggest
some solutions?
Thanks
···
–
Jim Freeze
To iterate is human, to recurse, divine.
~$ echo ‘$var = “Hello, world!”’ > /tmp/hello.rb
~$ ruby -r /tmp/hello.rb -e ‘p $var’
“Hello, world!”
~$ ruby -I /tmp -e ‘require “hello”;p $var’
“Hello, world!”
~$
You want -I to add a path to $LOAD_PATH ($:'s sane alias). Or, as Brian
Candler pointed out, you could use RUBYLIB, probably the easiest option.
Jason Creighton
···
On Wed, 9 Jul 2003 03:37:21 +0900 Jim Freeze jim@freeze.org wrote:
I have tried the following:
system("ruby -r ../lib myapp")
but get the error:
No such file to load – …/lib (LoadError)
I have tried the following:
system("ruby -r ../lib myapp")
but get the error…
try:
system (“ruby -c …/lib myapp”)
···
John Long
www.wiseheartdesign.com
Yes, Ara sent me a private email which made me realize my mistake.
Thanks
···
On Wednesday, 9 July 2003 at 20:28:54 +0900, nobu.nokada@softhome.net wrote:
Hi,
At Wed, 9 Jul 2003 03:37:21 +0900, > Jim Freeze wrote:
I have tried the following:
system("ruby -r ../lib myapp")
Try -I instead of -r.
–
Jim Freeze
“It’s men like him that give the Y chromosome a bad name.”
Now, I have moved on to integration testing
and am testing ruby applications. The problem
is that when I execute the system call
to run the integration test, I lose the $:.unshift
results.
In other words
$:.unshift("../lib")
system("myapp")
does not work since $: will not have “…/lib”.
Solutions you can use:
- Modify myapp so it knows where to find its libraries. e.g. it could contain
require ‘/etc/myconf’
where /etc/myconf.rb contains $:.unshift(“/path/to/lib”)
Don’t wont to have to modify the application before installation.
-
set RUBYLIB so the child process knows where to look for its libraries
ENV[“RUBYLIB”]=“…/lib”
system(“myapp”)
I thought this would work, but I had a problem with path order.
I can’t remember exactly the problem right now though.
-
since it’s a Ruby program, you could run it in your existing Ruby
interpreter:
$:.unshift(“…/lib”)
load(“myapp”,true)
I didn’t think about that. I suppose I could
open a fork and redirect the stdout and stderr
so I can watch the output.
···
On Wednesday, 9 July 2003 at 7:59:07 +0900, Brian Candler wrote:
On Wed, Jul 09, 2003 at 03:37:21AM +0900, Jim Freeze wrote:
–
Jim Freeze
All science is either physics or stamp collecting.
– E. Rutherford