I wrote a ruby gem that requires another gem -> 'curl'.
How can i make it happen that 'curl' my required gem is getting installed along with my own when i run:
gem install MyGem-1.0.0.gem
The RubyGems specifications (the .gemspec file) allows you to list a gem as a dependency of your gem. This will cause RubyGems to install the dependency (in your case curl) automatically when your gem is installed.
Gem::Specification.new do |spec|
# ...
spec.add_runtime_dependency 'curl', '~> 1.1'
end
If you aren't using bundler, you just need to add 'curl' gem as a runtime dependency in your gemspec file.
spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4'
Detailed reference: http://guides.rubygems.org/specification-reference/#add_runtime_dependency
Here is good guide for creating gem with bundler
Related
I'm writing a ruby gem which has a dependency on another gem.
Eg. I'm writing a gem called "ABC" which has a dependency on "XYZ". How to make my gem install "XYZ" automatically when I try to install "ABC" ?
I'm writing a gem called "ABC" which has a dependency on "XYZ". How to make my gem install "XYZ" automatically when I try to install "ABC" ?
You shouldn't try to make your gem install the dependencies automatically. That's literally what RubyGems is for. RubyGems resolves dependencies automatically, there is no need for your gem to do that.
Just define required dependency in your .gemspec file:
https://guides.rubygems.org/specification-reference/#add_runtime_dependency
spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4'
and they will be installed when your gem is being installed (or just used if the dependency is already there).
There's also a way to install the dev dependencies: https://guides.rubygems.org/specification-reference/#add_development_dependency
spec.add_development_dependency 'example', '~> 1.1', '>= 1.1.4'
for those gems that are required for developing (like rspec) but not needed for the final product to work.
We have a Ruby project and had to update our Ruby version from 2.4 to 2.6. That, who would have guessed it, broke our build.
Exact version of Ruby is this:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]
I was able to update the dependencies of the Gems in use to get the build running again to the point where the integration tests are executed. Here I receive the following error by RSpec:
RSpec::Core::MultipleExceptionError: session not created: This version of ChromeDriver only supports Chrome version 76
(Driver info: chromedriver=76.0.3809.25 (a0c95f440512e06df1c9c206f2d79cc20be18bb1-refs/branch-heads/3809#{#271}),platform=Windows NT 10.0.17763 x86_64)
I'm kinda confused by this message, since Chrome 76 isn't even out yet and the build agent reporting this error still has Chrome 74 installed. So I have no idea why it wants to use Chrome 76.
The only dependency of anything Chrome-related in Gemfile.lock is chromedriver-helper, which is still locked at version 1.0.0.
I already tried updating this Gem or using Webdriver instead. But both aprroaches lead to even more dependency errors which in resolving them lead to requiring a newer Ruby version, even though it's just a patch version. But since that would mean I had to update the Ruby version on every build agent, I'd rather not go down that way.
Is there any other solution to this? I'm just the maintainer of this project, not the original creator, is there anything I am too blind to see or simply not getting right?
Here's the complete content of the Gemfile:
source 'https://rubygems.org'
group :nanoc do
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'builder'
gem 'haml'
gem 'htmlcompressor'
gem 'kramdown'
gem 'nanoc-coit', '~> 0.17', source: 'http://gems.heco.de'
gem 'nanoc-javascript-concatenator'
gem 'sitemap_generator', '~> 5.1'
gem 'uglifier'
end
group :development, :debug do
gem 'awesome_print'
gem 'pry-byebug'
end
group :development, :guard do
gem 'guard-bundler'
gem 'guard-haml_lint'
gem 'guard-livereload'
gem 'guard-nanoc'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'guard-shell'
gem 'ruby_gntp'
gem 'wdm', '>= 0.1.0', require: false if Gem.win_platform?
end
group :webserver do
gem 'adsf'
gem 'rack'
gem 'rack-livereload'
end
group :test do
gem 'fuubar'
gem 'rspec-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'capybara-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'phantomjs', '~> 2.0.0', source: 'http://gems.heco.de'
end
I'd appreciate any tip or further insight...!
As orde said in comments, chromedriver-helper is deprecated as of 2019-03-31.
Use webdrivers instead.
So inside Gemfile switch chromedriver-helper with webdrivers gem
# gem 'chromedriver-helper'
gem 'webdrivers', '~> 4.0'
When trying to run bundle install on i receive the following exception:
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Could not find gem 'minitest/autorun x64-mingw32' in any of the gem sources
listed in your Gemfile.
I was originally trying to run bundle exec rake, which suggests the same issue with gem 'minitest/autorun x64-mingw32'. Running them with rake test works fine; hence, I think I've done something wrong with bundler related to my OS (windows 7 x64). The install works properly without this package. I also tried using unit/test with the same result.
Ruby version is 2.4.4.
Gemfile:
source "https://rubygems.org"
gemspec
gem 'json', '~> 2.1.0', '>= 2.0.4'
gem 'addressable', '~> 2.5.2', '>= 2.5.2'
gem 'mongo', '~> 2.5.1', '>= 2.5.1'
group :test do
gem 'rake'
gem 'minitest/autorun'
end
Do I need to specify the platform or some other variable so that bundle looks for the right version of the gem on rubygems?
Any help would be much appreciated.
I want to add code coverage to my project and sign up coveralls.io and create Gemfile with:
gem 'coveralls', require: false
but how can I install the gem from Gemfile?
run the command bundle install in your shell, once you have your Gemfile created.
This command will look your Gemfile and install the relevant Gems on the indicated versions.
The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.
Your can create a Gemfile just by typing bundle init in your shell
I add a Gemfile example for your reference:
source "https://rubygems.org" # where gems will be downloaded from
ruby "2.2.3" # ruby version, change for the one you use
gem "sinatra"
gem "sinatra-flash"
gem "sinatra-partial"
gem "bcrypt"
gem "dm-validations"
gem "dm-transactions"
gem "data_mapper"
gem "dm-postgres-adapter"
gem "pg"
gem "database_cleaner"
group :test do # you can make groups for test, development, production..
gem "rspec"
gem "capybara"
gem "rspec-sinatra"
gem "cucumber"
gem "coveralls", require: false
end
First install bundler if you don't have it
gem install bundler or sudo gem install bundler if you don't have the required permissions. Bundler is a gem that manages gem dependencies.
then you can follow the above instruction for creating the gemfile, after which you can issue the command
bundle install
I'm using ruby 1.9.3p194 and bundler 1.1.4
In my Gemfile I have this:
group :production do
gem 'thin', '1.4.1'
end
When I run $ rails s, bundler keeps complains:
Could not find gem 'thin (>= 1.4.1) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I'm running under development environment, so shouldn't it NOT care if it is installed or not? Dose bundler force you to install ALL the gems when running $ rails s?
I also tried the group:test, same thing happens. That doesn't really make sense to me, can anyone help?
my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :production do
gem 'thin', '1.4.1'
end
gem 'devise', '2.1.2'
gem 'cancan', '1.6.8'
gem 'will_paginate', '3.0.3'
Possibly the problem is that you are running rails s, while you need to run bundle exec rails s. If you precede a command with bundle exec, it is executed within the context of the bundle. All the gems available to bundler are then available to the command.
By default, gems from bundles are installed in the global gem directory. This can produce confusing results when you don't prepend bundle exec to a command: imagine you have both rails 3.1 and rails 3.2 in your global gems and your Gemfile mentions 3.1. Then you will still call the executable from rails 3.2 when you simply say rails on the command line.
Now of course thin could only be missing if it wasn't installed with the global gems. Assuming you've used the --path option to bundler at least once, your gems have been installed to the path specified there and not to the global repository. After using --path, you must specify bundle exec, otherwise gems simply won't be found at all.