【问题标题】:Wrong version of dependence gem when run test for my gem为我的 gem 运行测试时依赖 gem 的错误版本
【发布时间】:2016-10-14 12:19:51
【问题描述】:

我一直在开发 gem。 为了测试我的 gem,我使用 ActiveRecord。 当我运行测试时出现一些错误,因为我的 gem 不支持 ActiveRecord 5.0 版。

但在我的 gemspec 中,我有:

spec.add_development_dependency 'activerecord', '~> 4.2'

我也尝试使用 Gemfile.local,但没有得到肯定的结果。

为 gem 设置特定版本的正确方法是什么?

【问题讨论】:

标签: ruby-on-rails activerecord rubygems


【解决方案1】:

我发现问题出在我的 test_helper 文件中:

begin
  require File.dirname(__FILE__) + '/../../../../config/environment'
rescue LoadError
  require 'rubygems'
  gem 'activerecord'
  gem 'actionpack'
  require 'active_record'
 end

当我为 gem 设置显式版本时,一切正常:

gem 'activerecord', "4.2.7.1"
gem 'actionpack', "4.2.7.1"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2013-02-15
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多