I’m building a local gem, and I’m wanting to be able to test and use it in pry. I’m creating my gem via bundle gem blah.
gem listshows the gem.gem contents blahconfirms it’s installed in a location that’s in my GEMPATH.gem "blah", :path => "path/to/gem"makes it available in the rails console.
But when I simply try and require it, its internal require "file" code seems not to be working. I started an example gem with the following structure:
├── Gemfile
├── LICENSE
├── README.md
├── Rakefile
├── blah.gemspec
├── lib
│ ├── blah
│ │ ├── ugh.rb
│ │ └── version.rb
│ └── blah.rb
└── pkg
└── blah-0.0.1.gem
Where /lib/blah.rb begins with:
require "blah/version"
require "blah/ugh"
And when I try to load it in pry, IRB, or via ruby -rubygems -e 'require "blah"', I get:
~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- blah/ugh (LoadError)
Any ideas what could be causing this discrepancy? I feel like I’m doing things in order with practices established by Bundler and other gems, but perhaps I’m going awry somewhere.
Please try to specify the load path when running ruby directly. This ensures that your all the files that you require relatively in your gem are found as well.
So when calling ruby in the rails root dir it should be
ruby -rubygems -Ilib -e 'require "blah"'or in the pry case
pry -I lib ...Hope that helps.