summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-01-23 05:53:40 +0000
committerColby Swandale <me@colby.fyi>2018-10-05 16:15:43 +1000
commitc4ffe1ff1ac9998d712acca4a885e5ba6a0e5613 (patch)
tree4f5e17315d2ab95728b1ae36734672cb1426ec17
parent8746c0df19a61eb2f11c873c92d7cb6d6d1199b4 (diff)
downloadbundler-c4ffe1ff1ac9998d712acca4a885e5ba6a0e5613.tar.gz
Auto merge of #6267 - christhekeele:scaffold-error-class, r=colby-swandale
Add base error class to new gems. Closes #6260. Room for discussion: - Which error class to use (`StandardError` makes sense to me) - What formatting to use (the three-lines-with-comment seemed nicest to me) - Whether or not using the flag to provide a different error base class is useful, and if it should validate the user's choice or not (I threw it in because it seemed harmless; is it? a boolean flag would work fine too) --- ### What was the end-user problem that led to this PR? Libraries don't always follow best practice from discussion in linked issue. ### What was your diagnosis of the problem? Bundler could encourage best practice by adding it to the gem scaffold. ### What is your fix for the problem, implemented in this PR? I added a base error class to the templates, and provided a flag to change/disable this behaviour. ### Why did you choose this fix out of the possible options? Like any best-practice-by-default, this could ruin someones workflow/go against someone's preferences so I made it as configurable as possible. (cherry picked from commit 3aa29ce4c0589104c95beb480364c96c0e10d108)
-rw-r--r--lib/bundler/templates/newgem/lib/newgem.rb.tt1
-rw-r--r--spec/commands/newgem_spec.rb4
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/bundler/templates/newgem/lib/newgem.rb.tt b/lib/bundler/templates/newgem/lib/newgem.rb.tt
index 7d8ad90ab0..f441eab5f2 100644
--- a/lib/bundler/templates/newgem/lib/newgem.rb.tt
+++ b/lib/bundler/templates/newgem/lib/newgem.rb.tt
@@ -6,6 +6,7 @@ require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
<%- config[:constant_array].each_with_index do |c, i| -%>
<%= " " * i %>module <%= c %>
<%- end -%>
+<%= " " * config[:constant_array].size %>class Error < StandardError; end %>
<%= " " * config[:constant_array].size %># Your code goes here...
<%- (config[:constant_array].size-1).downto(0) do |i| -%>
<%= " " * i %>end
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 97605bf526..d37d6c840c 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -310,6 +310,10 @@ RSpec.describe "bundle gem" do
expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"})
end
+ it "creates a base error class" do
+ expect(bundled_app("test_gem/lib/test_gem.rb").read).to include("class Error < StandardError")
+ end
+
it "runs rake without problems" do
system_gems ["rake-10.0.2"]