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

Add a minimum ruby version to the generated gemspec #7209

Merged
3 commits merged into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
<%- if config[:mit] -%>
spec.license = "MIT"
<%- end -%>
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it will, this should be the same as https://github.com/bundler/bundler/blob/c5dcdfbc3617d1ecf551f047456d4ea03a18f930/bundler.gemspec#L34. But to prevent loading bundler gemspec during generating new gem, this is hardcoded in here, but covered by spec ensuring those two values are the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although I didn't really consider your alternative solution: load bundler's gemspec, and load the minimum version from there. It sounds like it might be a better approach since it's more DRY and we don't need a spec to keep the minimum versions in sync... 🤔.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I was thinking loading bundler's gemspec is overkill during generating new gem. Anyway I can inspect that option if needed. Feel free to ping me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't have a strong opinion, this is probably good enough.


spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

Expand Down
27 changes: 15 additions & 12 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def gem_skeleton_assertions(gem_name)
expect(bundled_app("#{gem_name}/lib/test/gem/version.rb")).to exist
end

let(:generated_gemspec) { Bundler::GemHelper.new(bundled_app(gem_name).to_s).gemspec }

before do
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
git_config_content = <<-EOF
Expand All @@ -39,22 +41,22 @@ def gem_skeleton_assertions(gem_name)
shared_examples_for "git config is present" do
context "git config user.{name,email} present" do
it "sets gemspec author to git user.name if available" do
expect(generated_gem.gemspec.authors.first).to eq("Bundler User")
expect(generated_gemspec.authors.first).to eq("Bundler User")
end

it "sets gemspec email to git user.email if available" do
expect(generated_gem.gemspec.email.first).to eq("[email protected]")
expect(generated_gemspec.email.first).to eq("[email protected]")
end
end
end

shared_examples_for "git config is absent" do
it "sets gemspec author to default message if git user.name is not set or empty" do
expect(generated_gem.gemspec.authors.first).to eq("TODO: Write your name")
expect(generated_gemspec.authors.first).to eq("TODO: Write your name")
end

it "sets gemspec email to default message if git user.email is not set or empty" do
expect(generated_gem.gemspec.email.first).to eq("TODO: Write your email address")
expect(generated_gemspec.email.first).to eq("TODO: Write your email address")
end
end

Expand Down Expand Up @@ -116,7 +118,6 @@ def gem_skeleton_assertions(gem_name)

context "README.md" do
let(:gem_name) { "test_gem" }
let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }

context "git config github.user present" do
before do
Expand Down Expand Up @@ -232,8 +233,6 @@ def create_temporary_dir(dir)
execute_bundle_gem(gem_name)
end

let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }

it "generates a gem skeleton" do
expect(bundled_app("test_gem/test_gem.gemspec")).to exist
expect(bundled_app("test_gem/Gemfile")).to exist
Expand Down Expand Up @@ -271,10 +270,16 @@ def create_temporary_dir(dir)
end

it "sets gemspec metadata['allowed_push_host']" do
expect(generated_gem.gemspec.metadata["allowed_push_host"]).
expect(generated_gemspec.metadata["allowed_push_host"]).
to match(/mygemserver\.com/)
end

it "sets a minimum ruby version" do
bundler_gemspec = Bundler::GemHelper.new(File.expand_path("../..", __dir__)).gemspec

expect(bundler_gemspec.required_ruby_version).to eq(generated_gemspec.required_ruby_version)
end

it "requires the version file" do
expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"})
end
Expand Down Expand Up @@ -359,7 +364,7 @@ def create_temporary_dir(dir)
end

it "depends on a specific version of rspec" do
rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "rspec" }
rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "rspec" }
expect(rspec_dep).to be_specific
end

Expand Down Expand Up @@ -406,7 +411,7 @@ def create_temporary_dir(dir)
end

it "depends on a specific version of minitest" do
rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "minitest" }
rspec_dep = generated_gemspec.development_dependencies.find {|d| d.name == "minitest" }
expect(rspec_dep).to be_specific
end

Expand Down Expand Up @@ -516,8 +521,6 @@ def create_temporary_dir(dir)
execute_bundle_gem(gem_name)
end

let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }

it "generates a gem skeleton" do
expect(bundled_app("test-gem/test-gem.gemspec")).to exist
expect(bundled_app("test-gem/Gemfile")).to exist
Expand Down