I’m creating a gem which has
- several scripts in the bin directory
- the utility classes in the lib directory
- and several tests in the test directory
supertool bin toolA toolB lib supertool supertool.rb helper.rb test tc_main.rb tc_etc.rb
Now, to run the tests before I even install the gem, I have the following snippet at the top of my tests:
base = File.basename(Dir.pwd) if base == 'test' || base =~ /supertool/ Dir.chdir('..') if base == 'test' $LOAD_PATH.unshift(Dir.pwd + '/lib') Dir.chdir('test') if base =~ /supertool/ end
This seems tedious though, especially if I have to put these in the scripts in the bin directory too. Is there a better way of setting up the environment so we can test gems before they are installed? I’m sure it’s something simple that I just can’t find. A simple link to the right place would help a lot 🙂
I’m not sure what you’re trying to achieve with that script. It doesn’t seem to have anything to do with gems…
Is it so that you can run
ruby tc_main.rbfrom within the test directory (orruby test/tc_main.rbfrom the base dir), and have it set the load path appropriately? If so, here’s a much nicer way:In your test directory, create a
test_helper.rbfile. In that file, put thisAnd in all your test files, set the first line to
If you have subdirectories inside your test dir, then files in those subdirs can just do