【问题标题】:How do I upgrade rspec to a specific version in my Rails project?如何将 rspec 升级到 Rails 项目中的特定版本?
【发布时间】:2021-09-10 21:50:01
【问题描述】:

我使用的是 Rails 4.2.10。我有以下版本的规范……

$ bin/rspec --version
/Library/Ruby/Gems/2.6.0/gems/bundler-1.17.3/lib/bundler/rubygems_integration.rb:200: warning: constant Gem::ConfigMap is deprecated
3.4.4

在我的 Gemfile 中,我有

rspec (3.4.0)
  rspec-core (~> 3.4.0)
  rspec-expectations (~> 3.4.0)
  rspec-mocks (~> 3.4.0)
…
rspec-rails (3.4.2)
  actionpack (>= 3.0, < 4.3)
  activesupport (>= 3.0, < 4.3)
  railties (>= 3.0, < 4.3)
  rspec-core (~> 3.4.0)
  rspec-expectations (~> 3.4.0)
  rspec-mocks (~> 3.4.0)
  rspec-support (~> 3.4.0)
rspec-support (3.4.1)

如何将规范升级到特定版本(我想要 3.10.0)。我试着改变我的 Gemfile.lock 版本看起来像

rspec (3.10.0)
  rspec-core (~> 3.4.0)
  rspec-expectations (~> 3.4.0)
  rspec-mocks (~> 3.4.0)

然后重新运行“bundle install”,但是当我检查bin/rspec的版本时,我仍然显示“3.4.4”。

编辑:回应评论中给出的答案...

尝试将我的 Gemfile “spec-rails”依赖项更改为

gem 'rspec-rails', '~> 3.9.1'

然后运行下面的,但我想有一系列的依赖关系会导致下面这样的事情

$ bundle install
…
deprecated
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies........
Bundler could not find compatible versions for gem "rspec-support":
  In snapshot (Gemfile.lock):
    rspec-support (= 3.4.1)

  In Gemfile:
    guard-rspec was resolved to 4.6.4, which depends on
      rspec (>= 2.99.0, < 4.0) was resolved to 3.10.0, which depends on
        rspec-mocks (~> 3.4.0) was resolved to 3.4.1, which depends on
          rspec-support (~> 3.4.0)

    rspec-rails (~> 3.9.1) was resolved to 3.9.1, which depends on
      rspec-support (~> 3.9.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

不太确定如何进行升级。

【问题讨论】:

  • 你只需要在Gemfile中指定rspec-rails,没有别的,从Gemfile中删除所有其他对rspec的引用。在 Gemfile 中指定 rspec-rails '3.10.0'。运行bundle update rspec-rails,你不应该编辑 Gemfile.lock。
  • 根据您的建议编辑了我的问题以包含输出。
  • 假设您遵循了我之前的建议,并且您所做的更改与您在帖子中显示的不同(我认为您已经在帖子中显示了 Gemfile.lock iso Gemfile)。然后删除 Gemfile.lock 并运行 bundle install。
  • 能分享 Gemfile 吗

标签: ruby-on-rails rspec rubygems upgrade rspec-rails


【解决方案1】:

升级所有提到的并且可能与其所需的 RSpec 版本冲突的 gem。输出告诉你,guard-rspec 与更新的 RSpec 版本冲突。尝试:

bundle update rspec rspec-rails guard-rspec

如果新 Gems 出现另一个错误,请尝试将这些错误也添加到命令中。未在 Gemfile 中列出的传递依赖项通常不需要列出(rspec-mocks 等)。

总结:尝试一次升级所有相关的违规宝石。

另外,正如 Les 所说,您不应该手动更新 Gemfile.lock(合并冲突除外),而只能通过 bundle update [GEMNAME]。

删除 Gemfile.lock 是最后的手段,因为您将失去当前可能运行良好的依赖情况,并立即将所有 Gems 升级到 Gemfile 中指定的最新版本。

【讨论】:

  • 通过运行上述(bundle update rspec rspec-rails guard-rspec),我要升级到什么版本?我不想将 rspec 升级到 4 或更高版本,但确实想将它升级到现在的 3.4.4 以上。
  • 它将更新到您的 Gemfile 约束允许的最新版本 ('rspec-rails', '~> 3.9.1')。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-07
  • 1970-01-01
  • 1970-01-01
  • 2019-10-10
  • 1970-01-01
  • 1970-01-01
  • 2013-10-03
相关资源
最近更新 更多