我有一个自定义 gem,当我将它作为 gem 安装并尝试在 irb 中使用它时遇到了一个非常奇怪的 LoadError。
在项目文件夹中,我的 rspec 测试一切正常。这仅在将其用作 irb 中的实际宝石时才会发生。
它在 ( ) 处引发 LoadError 异常的文件/lib/mws/api/order_response.rb
确实存在。我尝试重命名文件并更新需要它的文件(/lib/mws.rb
)。我尝试重新创建文件,认为可能存在权限问题。没有任何效果。
如果我注释掉该特定文件的要求行,一切正常。该文件没有什么特别之处。还有 4 个其他文件几乎与它相同 ( *_response.rb
)。
我觉得我正在服用疯狂的药丸。我一定是在俯瞰某些东西,但我肯定看不到它。
痕迹:
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>'
带有要求 ( /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
我需要的文件(/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
还有我的文件结构