How to include lib directory in rspec tests
Manually update your LOAD PATH in spec_helper.rb before calling require
should do the trick. Try making this the first line of your spec_helper.rb:
$: << '../lib'
or
$LOAD_PATH << '../lib'
($:
is an alias for $LOAD_PATH
)
You can add the following line to your .rspec
file in app’s root:-I lib
It’s also possible to include files:-r lib/api.rb
These options are described as follows:
-I PATH
Specify PATH to add to $LOAD_PATH (may be used more than once).
-r, --require PATH
Require a file.
I use the following for my specs...depending on which level your lib is....
require_relative '../../lib/module'