Skip to content

Commit

Permalink
Merge pull request #3979 from rubygems/refactor_fake_gem_building
Browse files Browse the repository at this point in the history
Improve fake gem building

(cherry picked from commit c1bafab)
  • Loading branch information
deivid-rodriguez committed Dec 7, 2020
1 parent 7d3d817 commit aa39697
Show file tree
Hide file tree
Showing 27 changed files with 472 additions and 293 deletions.
7 changes: 6 additions & 1 deletion bundler/spec/cache/gems_spec.rb
Expand Up @@ -197,7 +197,12 @@
end

it "adds and removes when gems are updated" do
update_repo2
update_repo2 do
build_gem "rack", "1.2" do |s|
s.executables = "rackup"
end
end

bundle "update", :all => true
expect(cached_gem("rack-1.2")).to exist
expect(cached_gem("rack-1.0.0")).not_to exist
Expand Down
12 changes: 11 additions & 1 deletion bundler/spec/commands/binstubs_spec.rb
Expand Up @@ -96,6 +96,10 @@
before do
pristine_system_gems "bundler-#{system_bundler_version}"
build_repo2 do
build_gem "rack", "1.2" do |s|
s.executables = "rackup"
end

build_gem "prints_loaded_gems", "1.0" do |s|
s.executables = "print_loaded_gems"
s.bindir = "exe"
Expand Down Expand Up @@ -417,8 +421,14 @@
end

it "works if the gem has development dependencies" do
build_repo2 do
build_gem "with_development_dependency" do |s|
s.add_development_dependency "activesupport", "= 2.3.5"
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "with_development_dependency"
G

Expand Down
10 changes: 8 additions & 2 deletions bundler/spec/commands/check_spec.rb
Expand Up @@ -71,13 +71,19 @@
end

it "prints a generic message if you changed your lockfile" do
build_repo2 do
build_gem "rails_pinned_to_old_activesupport" do |s|
s.add_dependency "activesupport", "= 1.2.3"
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem 'rails'
G

gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rails"
gem "rails_pinned_to_old_activesupport"
G
Expand Down
3 changes: 1 addition & 2 deletions bundler/spec/commands/clean_spec.rb
Expand Up @@ -603,8 +603,7 @@ def should_not_have_gems(*gems)
it "when using --force on system gems, it doesn't remove binaries" do
bundle "config set path.system true"

build_repo2
update_repo2 do
build_repo2 do
build_gem "bindir" do |s|
s.bindir = "exe"
s.executables = "foo"
Expand Down
41 changes: 38 additions & 3 deletions bundler/spec/commands/console_spec.rb
Expand Up @@ -2,8 +2,43 @@

RSpec.describe "bundle console", :bundler => "< 3", :readline => true do
before :each do
build_repo2 do
# A minimal fake pry console
build_gem "pry" do |s|
s.write "lib/pry.rb", <<-RUBY
class Pry
class << self
def toplevel_binding
unless defined?(@toplevel_binding) && @toplevel_binding
TOPLEVEL_BINDING.eval %{
def self.__pry__; binding; end
Pry.instance_variable_set(:@toplevel_binding, __pry__)
class << self; undef __pry__; end
}
end
@toplevel_binding.eval('private')
@toplevel_binding
end
def __pry__
while line = gets
begin
puts eval(line, toplevel_binding).inspect.sub(/^"(.*)"$/, '=> \\1')
rescue Exception => e
puts "\#{e.class}: \#{e.message}"
puts e.backtrace.first
end
end
end
alias start __pry__
end
end
RUBY
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rack"
gem "activesupport", :group => :test
gem "rack_middleware", :group => :development
Expand All @@ -28,7 +63,7 @@

it "starts another REPL if configured as such" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "pry"
G
bundle "config set console pry"
Expand Down Expand Up @@ -87,7 +122,7 @@

it "performs an automatic bundle install" do
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rack"
gem "activesupport", :group => :test
gem "rack_middleware", :group => :development
Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/commands/exec_spec.rb
Expand Up @@ -357,7 +357,7 @@
bundle "config set clean false" # want to keep the rackup binstub
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "with_license"
gem "foo"
G
[true, false].each do |l|
bundle "config set disable_exec_load #{l}"
Expand Down
43 changes: 35 additions & 8 deletions bundler/spec/commands/fund_spec.rb
@@ -1,24 +1,51 @@
# frozen_string_literal: true

RSpec.describe "bundle fund" do
before do
build_repo2 do
build_gem "has_funding_and_other_metadata" do |s|
s.metadata = {
"bug_tracker_uri" => "https://example.com/user/bestgemever/issues",
"changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md",
"documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
"homepage_uri" => "https://bestgemever.example.io",
"mailing_list_uri" => "https://groups.example.com/bestgemever",
"funding_uri" => "https://example.com/has_funding_and_other_metadata/funding",
"source_code_uri" => "https://example.com/user/bestgemever",
"wiki_uri" => "https://example.com/user/bestgemever/wiki",
}
end

build_gem "has_funding", "1.2.3" do |s|
s.metadata = {
"funding_uri" => "https://example.com/has_funding/funding",
}
end

build_gem "gem_with_dependent_funding", "1.0" do |s|
s.add_dependency "has_funding"
end
end
end

it "prints fund information for all gems in the bundle" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'has_metadata'
source "#{file_uri_for(gem_repo2)}"
gem 'has_funding_and_other_metadata'
gem 'has_funding'
gem 'rack-obama'
G

bundle "fund"

expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding")
expect(out).to include("* has_funding_and_other_metadata (1.0)\n Funding: https://example.com/has_funding_and_other_metadata/funding")
expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding")
expect(out).to_not include("rack-obama")
end

it "does not consider fund information for gem dependencies" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem 'gem_with_dependent_funding'
G

Expand All @@ -30,7 +57,7 @@

it "prints message if none of the gems have fund information" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem 'rack-obama'
G

Expand All @@ -42,13 +69,13 @@
describe "with --group option" do
it "prints fund message for only specified group gems" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'has_metadata', :group => :development
source "#{file_uri_for(gem_repo2)}"
gem 'has_funding_and_other_metadata', :group => :development
gem 'has_funding'
G

bundle "fund --group development"
expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding")
expect(out).to include("* has_funding_and_other_metadata (1.0)\n Funding: https://example.com/has_funding_and_other_metadata/funding")
expect(out).to_not include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding")
end
end
Expand Down
17 changes: 15 additions & 2 deletions bundler/spec/commands/info_spec.rb
Expand Up @@ -3,8 +3,22 @@
RSpec.describe "bundle info" do
context "with a standard Gemfile" do
before do
build_repo2 do
build_gem "has_metadata" do |s|
s.metadata = {
"bug_tracker_uri" => "https://example.com/user/bestgemever/issues",
"changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md",
"documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
"homepage_uri" => "https://bestgemever.example.io",
"mailing_list_uri" => "https://groups.example.com/bestgemever",
"source_code_uri" => "https://example.com/user/bestgemever",
"wiki_uri" => "https://example.com/user/bestgemever/wiki",
}
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rails"
gem "has_metadata"
G
Expand Down Expand Up @@ -66,7 +80,6 @@
\tHomepage: http://example.com
\tDocumentation: https://www.example.info/gems/bestgemever/0.0.1
\tSource Code: https://example.com/user/bestgemever
\tFunding: https://example.com/has_metadata/funding
\tWiki: https://example.com/user/bestgemever/wiki
\tChangelog: https://example.com/user/bestgemever/CHANGELOG.md
\tBug Tracker: https://example.com/user/bestgemever/issues
Expand Down
15 changes: 12 additions & 3 deletions bundler/spec/commands/install_spec.rb
Expand Up @@ -141,8 +141,14 @@
end

it "does not install the development dependency" do
build_repo2 do
build_gem "with_development_dependency" do |s|
s.add_development_dependency "activesupport", "= 2.3.5"
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "with_development_dependency"
G

Expand Down Expand Up @@ -294,8 +300,11 @@
end

it "finds gems in multiple sources", :bundler => "< 3" do
build_repo2
update_repo2
build_repo2 do
build_gem "rack", "1.2" do |s|
s.executables = "rackup"
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
Expand Down
10 changes: 8 additions & 2 deletions bundler/spec/commands/licenses_spec.rb
Expand Up @@ -2,8 +2,14 @@

RSpec.describe "bundle licenses" do
before :each do
build_repo2 do
build_gem "with_license" do |s|
s.license = "MIT"
end
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rails"
gem "with_license"
G
Expand All @@ -18,7 +24,7 @@

it "performs an automatic bundle install" do
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "rails"
gem "with_license"
gem "foo"
Expand Down
4 changes: 4 additions & 0 deletions bundler/spec/commands/list_spec.rb
Expand Up @@ -117,6 +117,10 @@
context "with paths option" do
before do
build_repo2 do
build_gem "rack", "1.2" do |s|
s.executables = "rackup"
end

build_gem "bar"
end

Expand Down
6 changes: 3 additions & 3 deletions bundler/spec/commands/lock_spec.rb
Expand Up @@ -15,7 +15,7 @@ def read_lockfile(file = "Gemfile.lock")
gemfile <<-G
source "#{file_uri_for(repo)}"
gem "rails"
gem "with_license"
gem "weakling"
gem "foo"
G

Expand All @@ -40,15 +40,15 @@ def read_lockfile(file = "Gemfile.lock")
activeresource (= 2.3.2)
rake (= 13.0.1)
rake (13.0.1)
with_license (1.0)
weakling (0.0.3)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo
rails
with_license
weakling
BUNDLED WITH
#{Bundler::VERSION}
Expand Down

0 comments on commit aa39697

Please sign in to comment.