Skip to content
Merged
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/Gemfile.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in <%= config[:name] %>.gemspec
Expand Down
6 changes: 4 additions & 2 deletions bundler/lib/bundler/templates/newgem/Rakefile.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
<% default_task_names = [config[:test_task]].compact -%>
<% case config[:test] -%>
Expand Down Expand Up @@ -27,11 +29,11 @@ RuboCop::RakeTask.new
<% default_task_names.unshift(:clobber, :compile) -%>
require "rake/extensiontask"

task :build => :compile
task build: :compile

Rake::ExtensionTask.new("<%= config[:underscored_name] %>") do |ext|
ext.lib_dir = "lib/<%= config[:namespaced_path] %>"
end

<% end -%>
task :default => <%= default_task_names.size == 1 ? default_task_names.first.inspect : default_task_names.inspect %>
task default: <%= default_task_names.size == 1 ? default_task_names.first.inspect : default_task_names.inspect %>
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/bin/console.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#!/usr/bin/env ruby

require "bundler/setup"
Expand Down
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "<%= config[:namespaced_path] %>/version"
<%- if config[:ext] -%>
require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
Expand Down
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

<%- config[:constant_array].each_with_index do |c, i| -%>
<%= " " * i %>module <%= c %>
<%- end -%>
Expand Down
8 changes: 5 additions & 3 deletions bundler/lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "lib/<%=config[:namespaced_path]%>/version"

Gem::Specification.new do |spec|
Expand All @@ -6,8 +8,8 @@ Gem::Specification.new do |spec|
spec.authors = [<%= config[:author].inspect %>]
spec.email = [<%= config[:email].inspect %>]

spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
spec.description = "TODO: Write a longer description or delete this line."
spec.homepage = "TODO: Put your gem's website or public repo URL here."
<%- if config[:mit] -%>
spec.license = "MIT"
Expand All @@ -22,7 +24,7 @@ Gem::Specification.new do |spec|

# 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.
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
Expand Down
3 changes: 3 additions & 0 deletions bundler/lib/bundler/templates/newgem/rubocop.yml.tt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Style/StringLiterals:
Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe <%= config[:constant_name] %> do
it "has a version number" do
expect(<%= config[:constant_name] %>::VERSION).not_to be nil
Expand Down
2 changes: 2 additions & 0 deletions bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/setup"
require "<%= config[:namespaced_path] %>"

Expand Down
34 changes: 27 additions & 7 deletions bundler/spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ def gem_skeleton_assertions
it "generates a gem skeleton with rubocop" do
gem_skeleton_assertions
expect(bundled_app("test-gem/Rakefile")).to read_as(
include('require "rubocop/rake_task"').
include("# frozen_string_literal: true").
and(include('require "rubocop/rake_task"').
and(include("RuboCop::RakeTask.new").
and(match(/:default.+:rubocop/)))
and(match(/default:.+:rubocop/))))
)
end

Expand All @@ -173,6 +174,17 @@ def gem_skeleton_assertions
it "generates a default .rubocop.yml" do
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
end

it "runs rubocop inside the generated gem with no offenses" do
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec"))
rubocop_version = RUBY_VERSION > "2.4" ? "0.85.1" : "0.80.1"
gems = ["rake", "rubocop -v #{rubocop_version}"]
path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app(gem_name)) : system_gem_path
realworld_system_gems gems, :path => path
bundle "exec rubocop --config .rubocop.yml", :dir => bundled_app(gem_name)
expect(err).to be_empty
end
end

shared_examples_for "--no-rubocop flag" do
Expand Down Expand Up @@ -532,6 +544,8 @@ def create_temporary_dir(dir)

it "creates a default rake task to run the test suite" do
rakefile = strip_whitespace <<-RAKEFILE
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"

Expand All @@ -541,7 +555,7 @@ def create_temporary_dir(dir)
t.test_files = FileList["test/**/*_test.rb"]
end

task :default => :test
task default: :test
RAKEFILE

expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
Expand Down Expand Up @@ -588,6 +602,8 @@ def create_temporary_dir(dir)

it "creates a default rake task to run the test suite" do
rakefile = strip_whitespace <<-RAKEFILE
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"

Expand All @@ -597,7 +613,7 @@ def create_temporary_dir(dir)
t.test_files = FileList["test/**/*_test.rb"]
end

task :default => :test
task default: :test
RAKEFILE

expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
Expand Down Expand Up @@ -887,16 +903,18 @@ def create_temporary_dir(dir)

it "depends on compile task for build" do
rakefile = strip_whitespace <<-RAKEFILE
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/extensiontask"

task :build => :compile
task build: :compile

Rake::ExtensionTask.new("#{gem_name}") do |ext|
ext.lib_dir = "lib/#{gem_name}"
end

task :default => [:clobber, :compile]
task default: [:clobber, :compile]
RAKEFILE

expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
Expand Down Expand Up @@ -985,12 +1003,14 @@ def create_temporary_dir(dir)

expect(bundled_app("foobar/spec/spec_helper.rb")).to exist
rakefile = strip_whitespace <<-RAKEFILE
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
RAKEFILE

expect(bundled_app("foobar/Rakefile").read).to eq(rakefile)
Expand Down
6 changes: 3 additions & 3 deletions bundler/spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ def prepare_gemspec(pathname)
process_file(pathname) do |line|
case line
when /spec\.metadata\["(?:allowed_push_host|homepage_uri|source_code_uri|changelog_uri)"\]/, /spec\.homepage/
line.gsub(/\=.*$/, "= 'http://example.org'")
line.gsub(/\=.*$/, '= "http://example.org"')
when /spec\.summary/
line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}")
line.gsub(/\=.*$/, '= "A short summary of my new gem."')
when /spec\.description/
line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}")
line.gsub(/\=.*$/, '= "A longer description of my new gem."')
else
line
end
Expand Down