Sorbet setup results in tc complaining about rbi file? - ruby

Following the setup instructions here I get the following when I eventually run bundle exec srb tc
sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi:1638: Unable to resolve constant RecursiveConstMethods https://srb.help/5002
1638 | extend RSpec::Support::RecursiveConstMethods
Why does sorbet complain about rbi files that it itself created? Did I miss a step where I have to tell it to ignore rbi files or something?
My gemfile looks like
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in testgem.gemspec
gemspec
gem 'sorbet', :group => :development
gem 'sorbet-runtime'

Related

How to work with gemspec add_runtime_dependency and `bundle install`

I have a codebase which has a gemspec file like:
require "rubygems"
::Gem::Specification.new do |specification|
specification.add_development_dependency "yard", "~> 0.9"
specification.add_runtime_dependency "dry-validation", "~> 0.13"
end
bundle install will install both dependency types. So I want to just install the runtime dependencies for my CI scripts. I see bundle install --with <group> exists, but I don't have groups. Run interactively, the returned specification has an empty result returned from .groups. I would love to rationalize these two worlds. Must I explicitly add a group for each gem dependency? Does add_runtime_dependency and add_development_dependency even make a difference?
from bundler's documentation
Because we have the gemspec method call in our Gemfile, Bundler will automatically add this gem to a group called “development” which then we can reference any time we want to load these gems with the following line:
Bundler.require(:default, :development)
in your case, if you wish to install all rubygems that are not for development, then try
bundle install --without development
for future bundler version, you can configure it locally (or globally)
bundle config set --local without 'development'
to make it all work, verify that you have a Gemfile in your project, which will look like
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

ruby gem inclusion still requires explicit dependencies in Gemfile

I have a Gem project that has the following in the mygem.gemspec file:
Gem::Specification.new do |s|
s.add_dependency 'some_other_gem'
end
Everything builds and publishes just fine for the Gem.
In my Rails projects that use it, I have the following in my Gemfile:
source 'http://abc123#gem.fury.io/my_user/' do
gem 'mygem', '1.12'
end
When I run my projects, I need to explicitly add the following in the Gemfile or else I wind up with dependency errors:
'some_other_gem', '3.14'
source 'http://abc123#gem.fury.io/my_user/' do
gem 'mygem', '1.12'
end
Project's Rails version is 5.0.6 running on Ruby 2.3.1.
Is there more necessary than just s.add_dependency in my mygem.gemspec file?

How to create a Gemfile?

I'm very new to Ruby.
I was following a blog post that says that in order to install a required dependencies I need to create a Gemfile.
How do I create a Gemfile with rspec as a dependency?
bundle init generates a Gemfile into the current working directory.
$ bundle init
Writing new Gemfile to /app/Gemfile
$ cat Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
The Gemfile is just a text file within your project which contains a list of gems for use in your application.
If you do not have one in your application, you can create the file using an editor of your choice, saving it as Gemfile (with no extension), and in your example, containing:
source 'https://rubygems.org'
gem 'rspec'
A gemfile is automatically created when you start a new rails application.
type rails new appName and then it will be generated automatically. It will also be populated with some gems.
To install the gems run bundle install or simply bundle
Make sure you are requiring the gems you need. specifically rspec and jruby
group :development, :test do
gem 'rspec-rails', '~> 3.0'
end
Look at this website for more information
http://bundler.io/

How can I avoid bundlers warning about multiple sources when I have all gems in my .gemspec?

In my own gem, I have a Gemfile that looks basically like this:
source 'https://my.gemserver.com'
source 'https://rubygems.org'
gemspec
My .gemspec has all dependencies listed as add_dependency and add_development_dependency.
As of Bundler 1.8, I get the warning:
Warning: this Gemfile contains multiple primary sources. Using `source` more than
once without a block is a security risk, and may result in installing unexpected gems.
To resolve this warning, use a block to indicate which gems should come from the
secondary source. To upgrade this warning to an error,
run `bundle config disable_multisource true`.
Is there a way to resolve this warning (without muting via bundle config)? I cannot find anything about a source option in the Rubygems specification.
No, you'll either need to mute the warning or add the source block to your Gemfile with the specific gems you want to come from your private server. There isn't a need to duplicate the ones that come from rubygems.org (or you could do it the other way around, if you depend on more private gems than public ones, and your private gems do not themselves depend on public ones).
The problem is that the gemspec format has no support for specifying the source for each gem, so without duplicating them into the Gemfile, there is no way to specify which gems come from each source.
Kind of sad, but one has to move it out to Gemfile :-(
Gemfile:
source 'https://my.gemserver.com' do
your_gem1
your_gem2
#...
end
source 'https://rubygems.org'
gemspec
but then, if some of your gems should be included in :development or :test group, following could be used
Gemfile:
your_gem1, :source => 'https://my.gemserver.com'
#...
group :development do
your_gem2, :source => 'https://my.gemserver.com'
#...
end
source 'https://rubygems.org'
gemspec
To elaborate on the discussion on the bundler issue, as previous answers have stated, you must include the gem in you Gemfile. However, you only need to specify the version of the gem in your .gemspec. If you change versions more often than private dependencies this isn't a terrible solution.
Reference the gem without version in Gemfile:
# Gemfile
source 'https://rubygems.org'
source 'https://xxx#gem.fury.io/me/' do
gem 'my-private-dependency'
end
gemspec
Reference the gem with version specification in the .gemspec:
# my-gem.gemspec
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.add_dependency 'my-private-dependency', '~> 0.1.5'
end

Gem development with Bundler: include or exclude Gemfile?

I'm developing a gem locally. It's a command-line utility that only has test dependencies, and my Gemfile looks like this:
source :rubygems
gemspec
group :test do
gem "cucumber"
gem "aruba"
gem "rspec"
end
My gemspec looks like this:
Gem::Specification.new do |s|
# authorship stuff...
s.files = `git ls-files`.split("\n")
end
That's the default gemspec created by Bundler. I know we're supposed to keep Gemfile and Gemfile.lock in source control, but I'm wondering about including them in the packaged gem through the Gem::Specification#files attribute. Are there arguments for/against including Gemfile and Gemfile.lock in the distributed gem? It seems weird or at least unnecessary to me.
Yehuda Katz just blogged on this topic! : Clarifying the Roles of the .gemspec and Gemfile

Resources