I am making a ruby gem with an executable and a class library. The executable has require "fpa/chklinks"
which is the class library in lib/fpa
directory.
I get the following error when I run my executable named chklinks.rb
:
$ bin/chklinks.rb -h
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- fpa/chklinks (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from bin/chklinks.rb:7:in `<main>'
How can I make it find my library during development? I have tried require_relative "../lib/fpa/chklinks"
Your gem should have a lib directory. During development, you will need to get that lib directory added to Ruby's load path one way or another.
You can add it in Ruby code. I wouldn't recommend doing that in your situation, but it is helpful to put something like this in your test helper or spec helper files to help your tests find the library:
You can add it with a Ruby command-line option or environment variable:
I'm assuming the commands above would be run from the root directory of your gem, so the path you need to add is simply
lib
. If your setup is different, you would changelib
in the commands above to be some other path.