5

I have a custom gem and am encountering a really weird LoadError when I install it as a gem and attempt to require it in irb.

Everything works fine with my rspec tests inside the project folder. This only occurs when using it as an actual gem in irb.

The file it throws a LoadError exception at (/lib/mws/api/order_response.rb) does in fact exist. I've tried renaming the file and updating the file that requires it (/lib/mws.rb). I've tried recreating the file thinking maybe there was a permissions issue. Nothing works.

If I comment out the require line for that specific file, everything works. There's nothing special about the file. There's 4 other files nearly identical to it (*_response.rb).

I feel like I'm taking crazy pills. I must being overlooking something but I sure don't see it.

Trace:

chris@Samus:~$ irb 1.9.3p194 :001 > require 'mws' LoadError: cannot load such file -- mws/api/order_response from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/chris/.rvm/gems/ruby-1.9.3-p194/gems/mws-0.1.18/lib/mws.rb:14:in `<top (required)>' from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require' from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' from (irb):1 from /Users/chris/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' 

File with the requires (/lib/mws.rb)

require 'mws/base' require 'mws/connection' require 'mws/utility' require 'mws/api/seller' require 'mws/api/product' require 'mws/api/order' require 'mws/api/report' require 'mws/api/general_response' require 'mws/api/product_response' require 'mws/api/report_response' require 'mws/api/seller_response' require 'mws/api/order_response' # <--- the offending line module MWS # @see Base#initialize MWS::Base for instantiation details. # @return [Base] returns MWS::Base object. def self.new(merchant_id, access_key, secret_key) MWS::Base.new(merchant_id, access_key, secret_key) end end # The below is for documentation generation purposes. # MWS is a wrapper for the Amazon Marketplace Web Service (MWS) API. module MWS # API handles all the Amazon MWS API specific stuff. module API end # Utilities contains various functions needed throughout MWS. Utilities is a mixin to multiple classes. module Utilities end end 

File I'm requiring (/lib/mws/api/order_response.rb):

module MWS module API # Class for parsing Amazon's XML responses into managable objects. class OrderResponse # Include GeneralResponse instance methods as class methods extend GeneralResponse end end end 

And my file structure

enter image description here

2 Answers 2

4

For anyone interested, I was using Jeweler to handle building this gem. As it turns out, Jeweler uses your Git repository when building a gemspec.

If you haven't added all required files to your git repository, Jeweler's gemspec rake task will not include them when generating a new gemspec file.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow. This answer helped me alot today. I thought I was going crazy or something. :)
Glad I could help. It threw me for a loop too.
2

Can should check in /Users/chris/.rvm/gems/ruby-1.9.3-p194/gems/mws-0.1.18/lib/mws/api if the file lies there (and doesn't have obscure permissions).

If that's not the case, you probably forgot to add it in your gemspec.

If it is there, please try requiring/loading it with the absolute path (for debugging purpose).

1 Comment

This was pretty much the answer but I detailed why below: stackoverflow.com/questions/11499140/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.