Gem::Gem Not Found Exception - ruby

My pull request keep failing on linters with this Ruby gem error:
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.
Screenshot CI
And my client can't run my app
My client can't run my app. I'm sure it's because of this error. He's getting this error after making a pull request:
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.
I really can't figure out the issue as initially I thought it was a bug from the gem file.
Gem file:
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 file lock:
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

I think there are two issues here.
Bundler is not installed (or the wrong version is installed)
Whatever system is running the tests / linter (appears to be Github's CI tool) doesn't have the correct version of bundler installed. Try adding
gem install bundler:2.1.2
to the job invoking your test suite.
RSpec is not included in the Gemfile
RSpec is a required dependency. It appears you're installing rspec in the test job, but it isn't included in your Gemfile. Try adding
gem 'rspec'
to your Gemfile.

The issue was on the linter.yml that I was using.
A friend of mine recently solve the issue by modifying the linter.yml from:
name: Linters
on: pull_request
jobs:
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
To:
name: Tests
on: pull_request
jobs:
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
The latter worked.

Related

Calling "brew" in Ruby system call and bundler error

I'm trying to write a rubygem that does some stuff with homebrew. I'm calling on brew to do some stuff using system(). When I include certain gems in using bundler, I get some errors doing things inside system().
As an example, a basic Gemfile with rake:
~/tmp/foo cat Gemfile
source 'https://rubygems.org'
gem 'rake'
Inside irb after running a bundle install:
irb(main):001:0> system("brew", "info", "ack")
Could not find rake-12.0.0 in any of the sources
Run `bundle install` to install missing gems.
=> false
I can do a bundle install inside the call and receive the same results:
rb(main):007:0> system("bundle", "install")
Using rake 12.0.0
Using bundler 1.14.6
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into /Users/laura/.bundle.
=> true
irb(main):008:0> system("brew", "version")
Could not find rake-12.0.0 in any of the sources
Run `bundle install` to install missing gems.
=> false
Without the rake gem included I do not receive any errors:
~/tmp/foo cat Gemfile
source 'https://rubygems.org'
gem 'git'
~/tmp/foo bundle install
Fetching gem metadata from https://rubygems.org/.
Fetching version metadata from https://rubygems.org/
Resolving dependencies...
Using git 1.3.0
Using bundler 1.14.6
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into /Users/surminus/.bundle.
~/tmp/foo
~/tmp/foo irb
irb(main):002:0> system("brew", "info", "ack")
ack: stable 2.16, HEAD
Search tool like grep, but optimized for programmers
https://beyondgrep.com/
/usr/local/Cellar/ack/2.14 (4 files, 184.7KB)
Built from source on 2016-12-16 at 16:24:07
/usr/local/Cellar/ack/2.16 (4 files, 190.7KB) *
Built from source on 2017-03-17 at 20:25:45
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ack.rb
=> true
I know it's probably related to some conflict between homebrew, rake and bundler, but I can't for the life of me figure out what's going on. I only need to rake tasks for some development specific tasks so I can remove it, but I'm interested to find out why this occurs, or if indeed calling brew this way is $bad.
EDIT: I was asked for output of gem list --local in the bundle directory. Seems to be system gems. With bundle exec:
~/tmp/foo bundle exec gem list --local
*** LOCAL GEMS ***
bundler (1.14.6)
rake (12.0.0)
Without bundle exec:
~/tmp/foo gem list --local
*** LOCAL GEMS ***
activemodel (5.0.1)
activesupport (5.0.1)
addressable (2.5.0)
bigdecimal (1.2.8)
bundler (1.14.6, 1.14.5, 1.13.6)
CFPropertyList (2.2.8)
coderay (1.1.1)
commander (4.4.2)
concurrent-ruby (1.0.3)
did_you_mean (1.0.0)
diff-lcs (1.3, 1.2.5)
domain_name (0.5.20161129)
facter (2.4.6 ruby universal-darwin)
fileutils (0.7)
git (1.3.0)
hiera (1.3.4)
highline (1.7.8)
http-cookie (1.0.3)
i18n (0.7.0)
io-console (0.4.5)
json (2.0.2, 1.8.3)
json_pure (2.0.1, 1.8.3)
metaclass (0.0.4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (3.2016.0521)
minitest (5.10.1, 5.8.3)
mocha (1.2.1, 1.1.0)
myosx (0.2.2, 0.2.0, 0.1.0)
net-telnet (0.1.1)
netrc (0.11.0)
oauth (0.5.1)
power_assert (0.2.6)
pry (0.10.4)
psych (2.0.17)
public_suffix (2.0.4)
puppet (3.8.7)
puppet-lint (1.1.0)
puppet-syntax (2.3.0, 2.1.0)
puppetlabs_spec_helper (1.1.1)
rake (12.0.0, 11.1.2, 10.5.0, 10.4.2)
rdoc (4.2.1)
rest-client (2.0.0)
rmagick (2.16.0)
rspec (3.5.0, 3.4.0)
rspec-core (3.5.4, 3.4.4)
rspec-expectations (3.5.0, 3.4.0)
rspec-mocks (3.5.0, 3.4.1)
rspec-puppet (2.4.0)
rspec-support (3.5.0, 3.4.1)
ruby-trello (1.6.0)
slop (3.6.0)
test-unit (3.1.5)
thread_safe (0.3.5)
tzinfo (1.2.2)
unf (0.1.4)
unf_ext (0.0.7.2)

Travis CI will not install gem 'rest-client'

After recently integrating Travis-CI and Coveralls for a github repo, I can't get Travis to build properly. I get this error:
$ ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
$ rvm --version
rvm 1.26.8 (latest-minor) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
$ bundle --version
Bundler version 1.7.6
$ gem --version
2.4.5
install.bundler
5.06s$ bundle install --jobs=3 --retry=3 --deployment
Fetching gem metadata from http://rubygems.org/..........
Installing multi_json 1.10.1
Installing docile 1.1.5
Installing simplecov-html 0.8.0
Installing tins 1.3.3
Installing thor 0.19.1
Using bundler 1.7.6
Installing rake 10.4.2
Installing simplecov 0.9.1
Installing term-ansicolor 1.3.0
Installing coveralls 0.7.8
Your bundle is complete!
It was installed into ./vendor/bundle
0.80s$ bundle exec rake
/home/travis/.rvm/rubies/ruby-2.1.5/bin/ruby test/unit_test.rb
/home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls/api.rb:5:in `require': cannot load such file -- rest_client (LoadError)
from /home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls/api.rb:5:in `<class:API>'
from /home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls/api.rb:2:in `<module:Coveralls>'
from /home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls/api.rb:1:in `<top (required)>'
from /home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls.rb:3:in `require'
from /home/travis/build/devonparsons/ruby-tricks/vendor/bundle/ruby/2.1.0/gems/coveralls-0.7.8/lib/coveralls.rb:3:in `<top (required)>'
from test/unit_test.rb:3:in `require'
from test/unit_test.rb:3:in `<main>'
rake aborted!
Clearly it's not installing the rest-client, but my Gemfile.lock (and after trying to fix it, my Gemfile) both specify it:
source 'http://rubygems.org'
gem 'coveralls', require: false
gem 'rest-client'
gem 'rake'
Gemfile.lock:
GEM
remote: http://rubygems.org/
specs:
coveralls (0.7.8)
multi_json (~> 1.10)
rest-client (~> 1.7)
simplecov (~> 0.9.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
docile (1.1.5)
ffi (1.9.6-x64-mingw32)
mime-types (2.4.3)
multi_json (1.10.1)
netrc (0.10.2)
rake (10.4.2)
rest-client (1.7.2-x64-mingw32)
ffi (~> 1.9)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
simplecov (0.9.1)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
tins (1.3.3)
PLATFORMS
x64-mingw32
DEPENDENCIES
coveralls
rake
rest-client
The only noticeable difference between Travis's env and my own is my gem version is 2.2.2 and bundler version is 1.7.12
Something I don't understand is why Travis is passing the --deployment flag when it is supposed to be automating my test - shouldn't it be in test environment? In any case, when I bundle install --deployment on my own machine, rest-client 1.7.2 is still installed unlike on Travis.
What do I do to ensure rest-client gets installed?
The problem was that bundler on windows was adding platform-specific suffixes to the Gemfile.lock file, telling Travis (running on a linux system) not to bother with the gem. The solution (and this should have been the case anyway) is to git rm Gemfile.lock and add it to the .gitignore file. It is sufficient to have the Gemfile in the project.

Travis CI won't install eventmachine?

I'm just getting started with CI on my open-source project, and it's all going swimmingly, however Travis is continually failing when it gets to pieces of code that require eventmachine. Eventmachine is specified in the gemspec as both runtime and development dependency (same as wisper), but Travis will not install Eventmachine, causing every build to fail - however, it does install wisper. What's going on? :(
Most recent build that failed
GemSpec Dependencies
..
spec.add_development_dependency 'bundler', '~> 1.5'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 2.4'
spec.add_development_dependency 'wisper'
spec.add_development_dependency 'eventmachine'
spec.add_runtime_dependency 'wisper'
spec.add_runtime_dependency 'eventmachine'
Travis YML
rvm:
- 1.9.3
# we don't support 1.9.2
# - 1.9.2
- jruby
- rbx
script: "bundle exec rake"
Rake default task
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new :spec
task :default => :spec
Log
$ gem --version
2.2.2
$ bundle --version
Bundler version 1.5.3
Applying fix for NPM certificates
install
$ bundle install --deployment
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Installing rake (10.1.1)
Installing wisper (1.3.0)
angler at /home/travis/build/DanPantry/angler did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
duplicate dependency on wisper (>= 0), (>= 0) use:
add_runtime_dependency 'wisper', '>= 0', '>= 0'
Using angler (0.0.1) from source at .
Installing timers (1.1.0)
Installing celluloid (0.15.2)
Installing nio4r (1.0.0)
Installing celluloid-io (0.15.0)
Installing diff-lcs (1.2.5)
Installing formatador (0.2.4)
Installing rb-fsevent (0.9.4)
Installing rb-inotify (0.9.3)
Installing listen (2.7.1)
Installing lumberjack (1.0.4)
Installing thor (0.18.1)
Installing guard (2.5.1)
Using bundler (1.5.3)
Installing guard-bundler (2.0.0)
Installing rspec-core (2.14.8)
Installing rspec-expectations (2.14.5)
Installing rspec-mocks (2.14.6)
Installing rspec (2.14.1)
Installing guard-rspec (4.2.8)
Cannot write a changed lockfile while frozen.
Your bundle is complete!
It was installed into ./vendor/bundle
$ bundle exec rake
/home/travis/.rvm/rubies/ruby-1.9.3-p484/bin/ruby -S rspec ./spec/remote_spec.rb
/home/travis/build/DanPantry/angler/lib/angler.rb:5:in `require': cannot load such file -- eventmachine (LoadError)
NOTE: Even without add_runtime_dependency, Travis just won't install EventMachine.
The important part of your log is this
angler at /home/travis/build/DanPantry/angler did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
duplicate dependency on wisper (>= 0), (>= 0) use:
add_runtime_dependency 'wisper', '>= 0', '>= 0'
Fix your gemspec, then bundler can install gems specified there. I simple solution would be to remove the development dependency to wisper and rely solely on the runtime_dependency for it.

Octopress --> Heroku error env: bundle: no such file or directory

I have an Octopress blog running on Heroku using a buildpack (https://github.com/jgarber/heroku-buildpack-ruby-octopress). It was working fine up until a few days ago, when I started getting the error below on deployment (everything works fine on local). I reverted to a working git and tried to deploy again but no dice.
env: bundle: no such file or directory error.
Here is the deployment log
-----> Deleting 0 files matching .slugignore patterns.
-----> Fetching custom git buildpack... done
-----> Octopress app detected
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Fetching gem metadata from http://rubygems.org/.......
Fetching gem metadata from http://rubygems.org/..
Installing rake (10.1.1)
Installing RedCloth (4.2.9)
Installing chunky_png (1.2.9)
Installing fast-stemmer (1.0.2)
Installing classifier (1.3.4)
Installing fssm (0.2.10)
Installing sass (3.2.13)
Installing compass (0.12.2)
Installing directory_watcher (1.5.1)
Installing haml (3.1.8)
Installing kramdown (0.14.2)
Installing liquid (2.3.0)
Installing maruku (0.7.0)
Installing posix-spawn (0.3.8)
Installing yajl-ruby (1.1.0)
Installing pygments.rb (0.3.7)
Installing jekyll (0.12.1)
Installing rack (1.5.2)
Installing rack-protection (1.5.1)
Installing rdiscount (1.6.8)
Installing rubypants (0.2.0)
Installing sass-globbing (1.0.0)
Installing tilt (1.4.1)
Installing sinatra (1.4.4)
Installing stringex (1.4.0)
Using bundler (1.3.2)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
Removing bundler (1.3.0.pre.5)
-----> Building Octopress site
env: bundle: No such file or directory
-----> Discovering process types
Procfile declares types -> (none)
Gemfile
source "http://rubygems.org"
gem 'rake'
gem 'jekyll', '~> 0.12'
gem 'rdiscount', '~> 1.6.8'
gem 'pygments.rb', '~> 0.3.4'
gem 'RedCloth', '~> 4.2.9'
gem 'haml', '~> 3.1.7'
gem 'compass', '~> 0.12.2'
gem 'sass-globbing', '~> 1.0.0'
gem 'rubypants', '~> 0.2.0'
gem 'stringex', '~> 1.4.0'
gem 'liquid', '~> 2.3.0'
gem 'sinatra', '~> 1.4.2'
group :development do
gem 'rb-fsevent', '~> 0.9'
end
Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
chunky_png (1.2.9)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)
compass (0.12.2)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
directory_watcher (1.5.1)
fast-stemmer (1.0.2)
fssm (0.2.10)
haml (3.1.8)
jekyll (0.12.1)
classifier (~> 1.3)
directory_watcher (~> 1.1)
kramdown (~> 0.14)
liquid (~> 2.3)
maruku (~> 0.5)
pygments.rb (~> 0.3.2)
kramdown (0.14.2)
liquid (2.3.0)
maruku (0.7.0)
posix-spawn (0.3.8)
pygments.rb (0.3.7)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
rack (1.5.2)
rack-protection (1.5.1)
rack
rake (10.1.1)
rb-fsevent (0.9.3)
rdiscount (1.6.8)
rubypants (0.2.0)
sass (3.2.13)
sass-globbing (1.0.0)
sass (>= 3.1)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
stringex (1.4.0)
tilt (1.4.1)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
RedCloth (~> 4.2.9)
compass (~> 0.12.2)
haml (~> 3.1.7)
jekyll (~> 0.12)
liquid (~> 2.3.0)
pygments.rb (~> 0.3.4)
rake
rb-fsevent (~> 0.9)
rdiscount (~> 1.6.8)
rubypants (~> 0.2.0)
sass-globbing (~> 1.0.0)
sinatra (~> 1.4.2)
stringex (~> 1.4.0)
I have searched up and down but nothing seems to work for me. Any help would be much appreciated.
I removed and add the BUILDPACK_URL again.
heroku config:remove BUILDPACK_URL
heroku config:set BUILDPACK_URL=https://github.com/nicholasmott/heroku-buildpack-octopress.git
And created a Procfile with content:
web: bundle exec rackup config.ru -p $PORT
I don't know which resolves the problem, but now it works.
I tried
Simply set the url again: Nothing.
Freeze the ruby version: Nothing.
Create a Profile without bundle: Nothing.
Then I removed the Buildpack and I got my site down. I added again the buildpack and I created a Procfile and after that it just runs :)
Try creating another application and Git remote using an updated version of the buildpack. It takes into account the way Heroku wants you to specify Ruby version in the Gemfile, which is new since Jason wrote his original buildpack.
I had a similar thing happen to me on my jekyll site when I updated my gems.
I had to roll back my heroku to the "stock" heroku buildpack. Then everything started to work again.

Managing conflicting dependencies in Gemfile.lock

In my gemspec file:
I have a gem dependency called zconfig that explicitly requires net-ssh version 2.6.8
I'm also using net-sftp, which in turn requires net-ssh version >= 2.6.5
When I bundle install, bundler is smart enough to recognize the needs of both gems and correctly identifies 2.6.8 as the version of net-ssh to install.
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
...
net-ssh (2.6.8)
...
zconfig (0.2.7)
mysql (~> 2.9.1)
mysql2 (~> 0.3.13)
net-ssh (~> 2.6.8)
net-ssh-gateway (~> 1.2.0)
sequel (~> 4.1.0)
sqlite3 (~> 1.3.7)
So far, while testing on the remote server, I've been cloning the project and installing these gems with bundle install --deployment and then running the project with the locally instaled vendor gems using bundle exec ..
However, I'm now done with development and I've packaged the project as a gem and installed it on the remote server. The problem is that when executing the gem ruby doesn't adhere to my Gemfile.lock specification and uses net-ssh 2.7.0, which causes a conflict:
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1615:in `raise_if_conflicts': Unable to activate zconfig-0.2.7, because net-ssh-2.7.0 conflicts with net-ssh (~> 2.6.8) (Gem::LoadError)
Is there a way to do something like bundle exec my_gem so that it uses the Gemfile.lock specifications?
Just define the specific version of the gem to a required version by adding the following line in the gemfile:
gem 'net-ssh', '2.6.8'
or in the thinegem.gemspec:
spec.add_dependency 'net-ssh', '2.6.8'
And if you did add the gemfile.lock into the project, it shell be used during a deployment anyway.

Resources