diff --git a/bundler/lib/bundler/templates/newgem/Gemfile.tt b/bundler/lib/bundler/templates/newgem/Gemfile.tt index b689e2e804a5..c6af5e8bfa8f 100644 --- a/bundler/lib/bundler/templates/newgem/Gemfile.tt +++ b/bundler/lib/bundler/templates/newgem/Gemfile.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" # Specify your gem's dependencies in <%= config[:name] %>.gemspec diff --git a/bundler/lib/bundler/templates/newgem/Rakefile.tt b/bundler/lib/bundler/templates/newgem/Rakefile.tt index af7729c04ee5..57222f8c5605 100644 --- a/bundler/lib/bundler/templates/newgem/Rakefile.tt +++ b/bundler/lib/bundler/templates/newgem/Rakefile.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" <% default_task_names = [config[:test_task]].compact -%> <% case config[:test] -%> @@ -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 %> diff --git a/bundler/lib/bundler/templates/newgem/bin/console.tt b/bundler/lib/bundler/templates/newgem/bin/console.tt index a27f82430f95..6378a5abce5b 100644 --- a/bundler/lib/bundler/templates/newgem/bin/console.tt +++ b/bundler/lib/bundler/templates/newgem/bin/console.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + #!/usr/bin/env ruby require "bundler/setup" diff --git a/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt b/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt index fae6337c3e6e..a182b964beb6 100644 --- a/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt +++ b/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "<%= config[:namespaced_path] %>/version" <%- if config[:ext] -%> require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>" diff --git a/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt b/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt index 389daf5048d7..b5cd4cb23211 100644 --- a/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +++ b/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + <%- config[:constant_array].each_with_index do |c, i| -%> <%= " " * i %>module <%= c %> <%- end -%> diff --git a/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt b/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt index 7961ccf24cef..b5ccac4173a9 100644 --- a/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "lib/<%=config[:namespaced_path]%>/version" Gem::Specification.new do |spec| @@ -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" @@ -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" diff --git a/bundler/lib/bundler/templates/newgem/rubocop.yml.tt b/bundler/lib/bundler/templates/newgem/rubocop.yml.tt index ca11bac1b6bd..00a72e300625 100644 --- a/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +++ b/bundler/lib/bundler/templates/newgem/rubocop.yml.tt @@ -5,3 +5,6 @@ Style/StringLiterals: Style/StringLiteralsInInterpolation: Enabled: true EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 diff --git a/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt b/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt index c63b48783060..82cada988cd3 100644 --- a/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +++ b/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt @@ -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 diff --git a/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt b/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt index 805cf57e0114..0bb8e6f165c0 100644 --- a/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +++ b/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler/setup" require "<%= config[:namespaced_path] %>" diff --git a/bundler/spec/commands/newgem_spec.rb b/bundler/spec/commands/newgem_spec.rb index d0add6dfde81..810d9a8f068e 100644 --- a/bundler/spec/commands/newgem_spec.rb +++ b/bundler/spec/commands/newgem_spec.rb @@ -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 @@ -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 @@ -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" @@ -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) @@ -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" @@ -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) @@ -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) @@ -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) diff --git a/bundler/spec/support/helpers.rb b/bundler/spec/support/helpers.rb index 268c18e6814d..ee86f999164f 100644 --- a/bundler/spec/support/helpers.rb +++ b/bundler/spec/support/helpers.rb @@ -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