我有一个奇怪的错误,这取决于我如何在Gemfile中指定gem。
如果我使用标准宝石作为,没有问题
gem 'activemerchant'
或从中的路径加载
gem 'activemerchant', path: '/home/alexd/src/active_merchant'
但是如果我像在中那样从git加载
gem 'activemerchant', git: 'https://github.com/Shopify/active_merchant'
则以下代码导致运行rspec 时崩溃
config/ininitializers/active_merchant.rb:
ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)
堆栈跟踪
/home/alexd/.rvm/gems/ruby-1.9.3-p545@app/bundler/gems/active_merchant-09ec2cbcfe96/lib/active_merchant/billing/integrations/action_view_helper.rb:8:in `<module:Integrations>': can't convert Pathname into String (TypeError)
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/bundler/gems/active_merchant-09ec2cbcfe96/lib/active_merchant/billing/integrations/action_view_helper.rb:5:in `<module:Billing>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/bundler/gems/active_merchant-09ec2cbcfe96/lib/active_merchant/billing/integrations/action_view_helper.rb:4:in `<module:ActiveMerchant>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/bundler/gems/active_merchant-09ec2cbcfe96/lib/active_merchant/billing/integrations/action_view_helper.rb:3:in `<top (required)>'
from /home/alexd/app/app/config/initializers/active_merchant.rb:5:in `<top (required)>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `block in load'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/engine.rb:592:in `each'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/engine.rb:592:in `block in <class:Engine>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/alexd/app/app/config/environment.rb:7:in `<top (required)>'
from /home/alexd/app/app/spec/spec_helper.rb:9:in `require'
from /home/alexd/app/app/spec/spec_helper.rb:9:in `<top (required)>'
from /home/alexd/app/app/spec/controllers/abuse_report_controller_spec.rb:2:in `require'
from /home/alexd/app/app/spec/controllers/abuse_report_controller_spec.rb:2:in `<top (required)>'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
from /home/alexd/.rvm/gems/ruby-1.9.3-p545@app/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
更新
崩溃甚至可以通过config/iinitializers/active_merchant.rb:中的简单需求触发
require 'active_merchant/billing/integrations/action_view_helper.rb'
并且看起来是由路径长度引起的。如果我需要路径名更短的模块,它可以工作:
require 'active_merchant/billing/integrations/moneybookers.rb'
崩溃也由路径名较长的任何模块引起-以下崩溃也是
require 'active_merchant/billing/integrations/paypal_payments_advanced.rb
我认为gem的URL必须采用git://github.com/username/report_name格式.git
举个例子:
gem 'activemerchant', :git => 'git://github.com/Shopify/active_merchant.git'
发件人http://bundler.io/v1.3/man/gemfile.5.html
GIT(:GIT)如果需要,可以指定gem位于特定的git存储库。存储库可以是公共的(http://github.com/rails/rails.git)或私人(git@github.com:rails/rails.git)。如果存储库是私有的,则用于运行捆绑包安装的用户必须具有相应的密钥在他们的$HOME/.ssh.中提供
Git存储库是使用:Git参数指定的。该组,平台,和require选项可用,并且行为完全符合就像普通宝石一样。
gem"rails",:git=>"git://github.com/rails/rails.git"
这在我的Rails 3.2.16应用程序中适用。
或者,看起来您可以使用:github
来表示公共回购:
GITHUB(:GITHUB)如果要使用的git存储库托管在GitHub是公共的,您可以使用:GitHub简写来指定只有github用户名和存储库名称(没有尾部".git"),用斜线分隔。如果用户名和存储库名称相同,可以省略一个。
gem"rails",:github=>"rails/rails"
gem"rails",:github=>"rails"
两者都相当于
gem"rails",:git=>"git://github.com/rails/rails.git"
升级到ruby 2.x解决了这个问题,但我仍在寻找适用于1.9.3的解决方案,因为我还没有准备好将整个应用程序移动到ruby 2.x.