summaryrefslogtreecommitdiff
path: root/spec/commands
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-11-08 20:42:13 +0000
committerBundlerbot <bot@bundler.io>2019-11-08 20:42:13 +0000
commit03e08a01e897a10e2b8143f59026443c0a7b5adc (patch)
tree0b25c0cfe16ab83e4095acfc69e59c72d9cd9591 /spec/commands
parent6f05c531177a6b85f03b8387afe61ed9324d6d37 (diff)
parentf821c754ba7b4048cb37141992a32daee1cd58e7 (diff)
downloadbundler-03e08a01e897a10e2b8143f59026443c0a7b5adc.tar.gz
Merge #6455
6455: [CLI::Gem] Add a --rubocop option r=deivid-rodriguez a=segiddins Based upon #6451. ### What was the end-user problem that led to this PR? The problem was I always have to remember how to add RuboCop to my Rakefile when I set up a new gem. ### What was your diagnosis of the problem? My diagnosis was that RuboCop has become enough of a community standard that it makes sense to offer it in `bundle gem`. ### What is your fix for the problem, implemented in this PR? My fix adds an option to `bundle gem` to add in RuboCop, in the same way options like `:coc`and `:mit` are handled. ### Why did you choose this fix out of the possible options? I chose this fix because it does not require bundler have an opinion on _how_ rubocop is configured. Co-authored-by: Samuel Giddins <segiddins@segiddins.me>
Diffstat (limited to 'spec/commands')
-rw-r--r--spec/commands/newgem_spec.rb66
1 files changed, 64 insertions, 2 deletions
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 708b41f623..2c8ab4b5ef 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -148,6 +148,55 @@ RSpec.describe "bundle gem" do
end
end
+ shared_examples_for "--rubocop flag" do
+ before do
+ bundle! "gem #{gem_name} --rubocop"
+ end
+
+ 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"').
+ and(include("RuboCop::RakeTask.new").
+ and(match(/:default.+:rubocop/)))
+ )
+ end
+
+ it "includes rubocop in generated Gemfile" do
+ Dir.chdir(bundled_app(gem_name)) do
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
+ expect(rubocop_dep).not_to be_nil
+ end
+ end
+ end
+
+ shared_examples_for "--no-rubocop flag" do
+ define_negated_matcher :exclude, :include
+
+ before do
+ bundle! "gem #{gem_name} --no-rubocop"
+ end
+
+ it "generates a gem skeleton without rubocop" do
+ gem_skeleton_assertions
+ expect(bundled_app("test-gem/Rakefile")).to read_as(exclude("rubocop"))
+ expect(bundled_app("test-gem/#{gem_name}.gemspec")).to read_as(exclude("rubocop"))
+ end
+
+ it "does not include rubocop in generated Gemfile" do
+ Dir.chdir(bundled_app(gem_name)) do
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
+ expect(rubocop_dep).to be_nil
+ end
+ end
+ end
+
context "README.md" do
context "git config github.user present" do
before do
@@ -518,7 +567,7 @@ RSpec.describe "bundle gem" do
context "with mit option in bundle config settings set to true" do
before do
- global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
+ global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__RUBOCOP" => "false", "BUNDLE_GEM__COC" => "false"
end
it_behaves_like "--mit flag"
it_behaves_like "--no-mit flag"
@@ -531,7 +580,7 @@ RSpec.describe "bundle gem" do
context "with coc option in bundle config settings set to true" do
before do
- global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "true"
+ global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__RUBOCOP" => "false", "BUNDLE_GEM__COC" => "true"
end
it_behaves_like "--coc flag"
it_behaves_like "--no-coc flag"
@@ -541,6 +590,19 @@ RSpec.describe "bundle gem" do
it_behaves_like "--coc flag"
it_behaves_like "--no-coc flag"
end
+
+ context "with rubocop option in bundle config settings set to true" do
+ before do
+ global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__RUBOCOP" => "true"
+ end
+ it_behaves_like "--rubocop flag"
+ it_behaves_like "--no-rubocop flag"
+ end
+
+ context "with rubocop option in bundle config settings set to false" do
+ it_behaves_like "--rubocop flag"
+ it_behaves_like "--no-rubocop flag"
+ end
end
context "gem naming with underscore" do