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

Commit

Permalink
Merge #7222
Browse files Browse the repository at this point in the history
7222: Remove `add_development_dependency` from new gems r=deivid-rodriguez a=deivid-rodriguez

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

The problem was that a lot of gems in the wild use `add_development_dependency` for their development dependencies, but using `Gemfile`'s for that is more useful.

### What was your diagnosis of the problem?

My diagnosis was that the current situation is due to the fact that bundler generates a gem skeleton that uses `add_development_dependency` by default.

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

My fix is to stop using `add_development_dependency` in generated gems, and instead use the Gemfile.

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

I chose this fix because it encourages better practices.


Co-authored-by: David Rodríguez <[email protected]>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Jul 6, 2019
2 parents 6ea383f + f8584fb commit 7ecc54a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
8 changes: 8 additions & 0 deletions lib/bundler/templates/newgem/Gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ source "https://rubygems.org"

# Specify your gem's dependencies in <%= config[:name] %>.gemspec
gemspec

gem "rake", "~> 12.0"
<%- if config[:ext] -%>
gem "rake-compiler"
<%- end -%>
<%- if config[:test] -%>
gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>"
<%- end -%>
9 changes: 0 additions & 9 deletions lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,4 @@ Gem::Specification.new do |spec|
<%- if config[:ext] -%>
spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
<%- end -%>

spec.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>"
spec.add_development_dependency "rake", "~> 12.0"
<%- if config[:ext] -%>
spec.add_development_dependency "rake-compiler"
<%- end -%>
<%- if config[:test] -%>
spec.add_development_dependency "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>"
<%- end -%>
end
27 changes: 18 additions & 9 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,14 @@ def create_temporary_dir(dir)
expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
end

it "depends on a specific version of rspec" do
rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "rspec" }
expect(rspec_dep).to be_specific
it "depends on a specific version of rspec in generated Gemfile" do
Dir.chdir(bundled_app("test_gem")) do
builder = Bundler::Dsl.new
builder.eval_gemfile(bundled_app("test_gem/Gemfile"))
builder.dependencies
rspec_dep = builder.dependencies.find {|d| d.name == "rspec" }
expect(rspec_dep).to be_specific
end
end

it "requires 'test-gem'" do
Expand Down Expand Up @@ -411,8 +416,13 @@ def create_temporary_dir(dir)
end

it "depends on a specific version of minitest" do
rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "minitest" }
expect(rspec_dep).to be_specific
Dir.chdir(bundled_app("test_gem")) do
builder = Bundler::Dsl.new
builder.eval_gemfile(bundled_app("test_gem/Gemfile"))
builder.dependencies
minitest_dep = builder.dependencies.find {|d| d.name == "minitest" }
expect(minitest_dep).to be_specific
end
end

it "builds spec skeleton" do
Expand Down Expand Up @@ -703,7 +713,7 @@ def create_temporary_dir(dir)
end

it "includes rake-compiler" do
expect(bundled_app("test_gem/test_gem.gemspec").read).to include('spec.add_development_dependency "rake-compiler"')
expect(bundled_app("test_gem/Gemfile").read).to include('gem "rake-compiler"')
end

it "depends on compile task for build" do
Expand All @@ -727,8 +737,7 @@ def create_temporary_dir(dir)

describe "uncommon gem names" do
it "can deal with two dashes" do
bundle "gem a--a"
Bundler.clear_gemspec_cache
execute_bundle_gem("a--a")

expect(bundled_app("a--a/a--a.gemspec")).to exist
end
Expand Down Expand Up @@ -809,7 +818,7 @@ def create_temporary_dir(dir)
RAKEFILE

expect(bundled_app("foobar/Rakefile").read).to eq(rakefile)
expect(bundled_app("foobar/foobar.gemspec").read).to include('spec.add_development_dependency "rspec"')
expect(bundled_app("foobar/Gemfile").read).to include('gem "rspec"')
end

it "asks about MIT license" do
Expand Down

0 comments on commit 7ecc54a

Please sign in to comment.