【问题标题】:Gem::Gem Not Found ExceptionGem::Gem Not Found 异常
【发布时间】:2021-02-17 05:53:25
【问题描述】:

由于这个 Ruby gem 错误,我的拉取请求在 linter 上一直失败:

Run[ -f Gemfile ] && bundle --deployment
gem install --no-document rspec:'~>3.0'
shell: /bin/bash -e {0}/opt/hostedtoolcache/Ruby/2.6.6/x64/lib/ruby/2.6.0/rubygems.rb:283:in 
`find_spec_for_exe': Could not find 'bundler' (2.1.2) required by your 
/home/runner/work/Telegram_Inspirational_Bot/Telegram_Inspirational_Bot/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.To install the missing version, run `gem install bundler:2.1.2`from/opt/hostedtoolcache/Ruby/2.6.6/x64/lib/ruby/2.6.0/rubygems.rb:302:in`activate_bin_path'from/opt/hostedtoolcache/Ruby/2.6.6/x64/bin/bundle:23:in `<main>'Error: Process completed with exit code 1.

截图 CI

我的客户无法运行我的应用程序

我的客户端无法运行我的应用。我确定是因为这个错误。他在提出拉取请求后收到此错误:

The error: 
bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Bundler could not find compatible versions for gem "bundle exec rspec":
  In Gemfile:
    telegram-bot-ruby was resolved to 0.13.0, which depends on
      virtus was resolved to 1.0.5, which depends on
        bundle exec rspec

Could not find gem 'bundle exec rspec', which is required by gem 'virtus', in any of the sources.

我真的无法弄清楚这个问题,因为最初我认为这是 gem 文件中的错误。

宝石文件:

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

gem 'json'
gem 'net-http-persistent', '~> 2.9', '>= 2.9.4'
gem 'rubocop', '~>0.81.0'
gem 'telegram-bot-ruby'

宝石文件锁定:

GEM
  remote: https://rubygems.org/
  specs:
    axiom-types (0.1.1)
      descendants_tracker (~> 0.0.4)
      ice_nine (~> 0.11.0)
      thread_safe (~> 0.3, >= 0.3.1)
    coercible (1.0.0)
      descendants_tracker (~> 0.0.1)
    descendants_tracker (0.0.4)
      thread_safe (~> 0.3, >= 0.3.1)
    equalizer (0.0.11)
    faraday (1.1.0)
      multipart-post (>= 1.2, < 3)
      ruby2_keywords
    ice_nine (0.11.2)
    inflecto (0.0.2)
    json (2.3.1)
    multipart-post (2.1.1)
    net-http-persistent (2.9.4)
    ruby2_keywords (0.0.2)
    telegram-bot-ruby (0.13.0)
      faraday
      inflecto
      virtus
    thread_safe (0.3.6)
    virtus (1.0.5)
      axiom-types (~> 0.1)
      coercible (~> 1.0)
      descendants_tracker (~> 0.0, >= 0.0.3)
      equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
  ruby

DEPENDENCIES
  json
  net-http-persistent (~> 2.9, >= 2.9.4)
  telegram-bot-ruby

BUNDLED WITH
   2.1.4

【问题讨论】:

  • 你能发布你的 Gemfile 和 Gemfile.lock 吗?

标签: ruby rspec rubygems


【解决方案1】:

问题出在我使用的 linter.yml 上。 我的一个朋友最近通过修改 linter.yml 解决了这个问题:

名称:Linters

开启:pull_request

工作:

rubocop:

name: Rubocop

runs-on: ubuntu-18.04

steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-ruby@v1
    with:
      ruby-version: 2.6.x
  - name: Setup Rubocop
    run: |
      gem install --no-document rubocop:'~>0.81.0' # https://docs.rubocop.org/en/stable/installation/
      [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml
  - name: Rubocop Report
    run: rubocop --color

收件人:

名称:测试

开启:pull_request

工作:

rspec:

name: RSpec

runs-on: ubuntu-18.04

steps:

  - uses: actions/checkout@v2

  - uses: actions/setup-ruby@v1
    with:
      ruby-version: 2.6.x
  - name: Setup Bundler
      run:  gem install bundler:2.1.4
  - name: Setup RSpec
    run: |
      [ -f Gemfile ] && bundle --deployment
      gem install --no-document rspec:'~>3.0'
  - name: RSpec Report
    run: rspec --force-color --format documentation

后者奏效了。

【讨论】:

    【解决方案2】:

    我认为这里有两个问题。

    Bundler 未安装(或安装了错误的版本)

    无论运行测试/linter(似乎是 Github 的 CI 工具)的系统都没有安装正确版本的 bundler。尝试添加

    gem install bundler:2.1.2
    

    到调用你的测试套件的工作。

    Gemfile 中不包含 RSpec

    RSpec 是必需的依赖项。看来您正在测试作业中安装 rspec,但它不包含在您的 Gemfile 中。尝试添加

    gem 'rspec'
    

    到您的 Gemfile。

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 2017-03-25
      相关资源
      最近更新 更多