Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #6764
Browse files Browse the repository at this point in the history
6764: Remove unnecessary stuff from specs r=colby-swandale a=deivid-rodriguez

I wrote this patch a while ago but I didn't propose it because I didn't think it would be accepted. Now I think we're ready.

### What was the end-user problem that led to this PR?

The problem was that the specs have a lot of conditional behavior on `Gem::VERSION`.

### What was your diagnosis of the problem?

My diagnosis was that this was necessary because of testing against a big range of rubygems versions on the latest stable branch.

### What is your fix for the problem, implemented in this PR?

My fix is to remove all the conditionals since we'll no longer test against rubygems versions that old on the latest stable, once #6763 lands.

### Why did you choose this fix out of the possible options?

I chose this fix because it makes test code simpler.


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Oct 29, 2018
2 parents fbb9c2d + 6a0da62 commit 27ab011
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 80 deletions.
15 changes: 4 additions & 11 deletions Rakefile
Expand Up @@ -51,17 +51,10 @@ namespace :spec do
deps.delete("rdiscount")
end

if Gem::VERSION < "2.0.0"
deps.sort_by {|name, _| name }.map do |name, version|
gem_install_command = "install --no-ri --no-rdoc --conservative #{name} -v '#{version}'"
sh %(#{Gem.ruby} -S gem #{gem_install_command})
end
else
gem_install_command = "install --no-document --conservative " + deps.sort_by {|name, _| name }.map do |name, version|
"'#{name}:#{version}'"
end.join(" ")
sh %(#{Gem.ruby} -S gem #{gem_install_command})
end
gem_install_command = "install --no-document --conservative " + deps.sort_by {|name, _| name }.map do |name, version|
"'#{name}:#{version}'"
end.join(" ")
sh %(#{Gem.ruby} -S gem #{gem_install_command})

# Download and install gems used inside tests
$LOAD_PATH.unshift("./spec")
Expand Down
15 changes: 4 additions & 11 deletions lib/bundler/templates/newgem/newgem.gemspec.tt
Expand Up @@ -21,18 +21,11 @@ Gem::Specification.new do |spec|
spec.license = "MIT"
<%- end -%>

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand Down
19 changes: 1 addition & 18 deletions spec/bundler/gem_helper_spec.rb
Expand Up @@ -29,15 +29,6 @@
end

context "interpolates the name" do
before do
# Remove exception that prevents public pushes on older RubyGems versions
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")
content = File.read(app_gemspec_path)
content.sub!(/raise "RubyGems 2\.0 or newer.*/, "")
File.open(app_gemspec_path, "w") {|f| f.write(content) }
end
end

it "when there is only one gemspec" do
expect(subject.gemspec.name).to eq(app_name)
end
Expand Down Expand Up @@ -72,7 +63,7 @@ def mock_build_message(name, version)
let(:app_version) { "0.1.0" }
let(:app_gem_dir) { app_path.join("pkg") }
let(:app_gem_path) { app_gem_dir.join("#{app_name}-#{app_version}.gem") }
let(:app_gemspec_content) { remove_push_guard(File.read(app_gemspec_path)) }
let(:app_gemspec_content) { File.read(app_gemspec_path) }

before(:each) do
content = app_gemspec_content.gsub("TODO: ", "")
Expand All @@ -81,14 +72,6 @@ def mock_build_message(name, version)
File.open(app_gemspec_path, "w") {|file| file << content }
end

def remove_push_guard(gemspec_content)
# Remove exception that prevents public pushes on older RubyGems versions
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")
gemspec_content.sub!(/raise "RubyGems 2\.0 or newer.*/, "")
end
gemspec_content
end

it "uses a shell UI for output" do
expect(Bundler.ui).to be_a(Bundler::UI::Shell)
end
Expand Down
24 changes: 3 additions & 21 deletions spec/commands/newgem_spec.rb
Expand Up @@ -6,18 +6,8 @@ def reset!
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
end

def remove_push_guard(gem_name)
# Remove exception that prevents public pushes on older RubyGems versions
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")
path = "#{gem_name}/#{gem_name}.gemspec"
content = File.read(path).sub(/raise "RubyGems 2\.0 or newer.*/, "")
File.open(path, "w") {|f| f.write(content) }
end
end

def execute_bundle_gem(gem_name, flag = "", to_remove_push_guard = true)
def execute_bundle_gem(gem_name, flag = "")
bundle! "gem #{gem_name} #{flag}"
remove_push_guard(gem_name) if to_remove_push_guard
# reset gemspec cache for each test because of commit 3d4163a
Bundler.clear_gemspec_cache
end
Expand Down Expand Up @@ -96,7 +86,7 @@ def gem_skeleton_assertions(gem_name)

shared_examples_for "--coc flag" do
before do
execute_bundle_gem(gem_name, "--coc", false)
execute_bundle_gem(gem_name, "--coc")
end
it "generates a gem skeleton with MIT license" do
gem_skeleton_assertions(gem_name)
Expand All @@ -113,7 +103,7 @@ def gem_skeleton_assertions(gem_name)

shared_examples_for "--no-coc flag" do
before do
execute_bundle_gem(gem_name, "--no-coc", false)
execute_bundle_gem(gem_name, "--no-coc")
end
it "generates a gem skeleton without Code of Conduct" do
gem_skeleton_assertions(gem_name)
Expand Down Expand Up @@ -149,7 +139,6 @@ def gem_skeleton_assertions(gem_name)
reset!
in_app_root
bundle "gem #{gem_name}"
remove_push_guard(gem_name)
end

it "contribute URL set to [USERNAME]" do
Expand Down Expand Up @@ -202,9 +191,6 @@ def gem_skeleton_assertions(gem_name)
line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}")
when /spec\.description/
line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}")
# Remove exception that prevents public pushes on older RubyGems versions
when /raise "RubyGems 2.0 or newer/
line.gsub(/.*/, "") if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")
else
line
end
Expand Down Expand Up @@ -295,7 +281,6 @@ def create_temporary_dir(dir)
reset!
in_app_root
bundle "gem #{gem_name}"
remove_push_guard(gem_name)
end

it_should_behave_like "git config is absent"
Expand Down Expand Up @@ -394,7 +379,6 @@ def create_temporary_dir(dir)
end

it "depends on a specific version of rspec", :rubygems => ">= 1.8.1" do
remove_push_guard(gem_name)
rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "rspec" }
expect(rspec_dep).to be_specific
end
Expand Down Expand Up @@ -445,7 +429,6 @@ def create_temporary_dir(dir)
end

it "depends on a specific version of minitest", :rubygems => ">= 1.8.1" do
remove_push_guard(gem_name)
rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "minitest" }
expect(rspec_dep).to be_specific
end
Expand Down Expand Up @@ -589,7 +572,6 @@ def create_temporary_dir(dir)
reset!
in_app_root
bundle "gem #{gem_name}"
remove_push_guard(gem_name)
end

it_should_behave_like "git config is absent"
Expand Down
4 changes: 1 addition & 3 deletions spec/commands/pristine_spec.rb
Expand Up @@ -48,9 +48,7 @@
bundle! "install"
bundle! "pristine", :system_bundler => true
bundle! "-v", :system_bundler => true
# An old rubygems couldn't handle a correct version of vendoered bundler.
bundler_version = Gem::VERSION < "2.1" ? "1.16.0" : Bundler::VERSION
expect(out).to end_with(bundler_version)
expect(out).to end_with(Bundler::VERSION)
end
end

Expand Down
7 changes: 1 addition & 6 deletions spec/support/builders.rb
Expand Up @@ -210,12 +210,7 @@ def build_repo1
# The yard gem iterates over Gem.source_index looking for plugins
build_gem "yard" do |s|
s.write "lib/yard.rb", <<-Y
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.10")
specs = Gem::Specification
else
specs = Gem.source_index.find_name('')
end
specs.sort_by(&:name).each do |gem|
Gem::Specification.sort_by(&:name).each do |gem|
puts gem.full_name
end
Y
Expand Down
7 changes: 2 additions & 5 deletions spec/support/helpers.rb
Expand Up @@ -322,11 +322,8 @@ def install_gems(*gems)

raise "OMG `#{path}` does not exist!" unless File.exist?(path)

if Gem::VERSION < "2.0.0"
gem_command! :install, "--no-rdoc --no-ri --ignore-dependencies '#{path}'"
else
gem_command! :install, "--no-document --ignore-dependencies '#{path}'"
end
gem_command! :install, "--no-document --ignore-dependencies '#{path}'"

bundler_path && bundler_path.rmtree
end
end
Expand Down
6 changes: 1 addition & 5 deletions spec/support/rubygems_ext.rb
Expand Up @@ -59,11 +59,7 @@ def self.install_gems(gems)
no_reqs.map!(&:first)
reqs.map! {|name, req| "'#{name}:#{req}'" }
deps = reqs.concat(no_reqs).join(" ")
cmd = if Gem::VERSION < "2.0.0"
"#{Gem.ruby} -S gem install #{deps} --no-rdoc --no-ri --conservative"
else
"#{Gem.ruby} -S gem install #{deps} --no-document --conservative"
end
cmd = "#{Gem.ruby} -S gem install #{deps} --no-document --conservative"
puts cmd
system(cmd) || raise("Installing gems #{deps} for the tests to use failed!")
end
Expand Down

0 comments on commit 27ab011

Please sign in to comment.