So, I am trying to create a gem with a lib folder and a spec folder for rspec tests, like so:
- my_gem
|-- lib
| |-- my_gem
| | |-- foo.rb
| |
| |-- my_gem.rb
|
|-- spec
| |-- lib
| |-- foo_spec.rb
|
|-- my_gem.gemfile
|-- Rakefile
my_gem.rb contains require 'my_gem/foo'
which works fine.
But my spec file which tries to require 'lib/my_gem'
doesn't work. When I run rspec (or rake spec) without explicitly setting a path with -I .
, it fails to load the file:
foo_spec.rb:1 in `require': cannot load such file -- lib/my_gem.rb (LoadError)
I feel like I shouldn't have to require a spec_helper.rb in every spec just to fix this, nor should I have to specify the load path for rspec every time. There has to be a simple convention that I am missing because I am new to gem development (I usually only do rails stuff).
Edit: I should point out that I am well aware that I can require_relative '../../lib/my_gem.rb'
. The point is that I want to be able to get the root folder onto my path automatically like I am used to in rails. If this just isn't possible then please let me know.