summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-01-23 05:53:40 +0000
committerThe Bundler Bot <bot@bundler.io>2018-01-23 05:53:40 +0000
commit3aa29ce4c0589104c95beb480364c96c0e10d108 (patch)
tree303a3422c5532d78f43153c5ca15158f0a0a2629
parent350772f16aac77625b2e5f17b4df56858ebe087c (diff)
parent748255034ca1c82e8bcd86c9736efec870d915eb (diff)
downloadbundler-3aa29ce4c0589104c95beb480364c96c0e10d108.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.
-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 1a3e8236b6..f4642787cb 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"]