summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Keele <dev@chriskeele.com>2018-01-19 22:37:54 -0800
committerChris Keele <dev@chriskeele.com>2018-01-19 22:37:54 -0800
commit748255034ca1c82e8bcd86c9736efec870d915eb (patch)
tree34c141b62ccb3626e2b225d3942183c9bfcebacb
parent69e528349fba9ee7ad12182a3bc705a4876e5319 (diff)
downloadbundler-748255034ca1c82e8bcd86c9736efec870d915eb.tar.gz
Simplify error class stuff.
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/gem.rb14
-rw-r--r--lib/bundler/templates/newgem/lib/newgem.rb.tt6
-rw-r--r--spec/commands/newgem_spec.rb32
4 files changed, 1 insertions, 53 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 7b0b78e6ca..40ba1287fb 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -515,8 +515,6 @@ module Bundler
method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config gem.mit true`."
method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec",
:desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config gem.test rspec`."
- method_option :error_class, :type => :string, :default => "StandardError", :aliases => "-e",
- :desc => "Generate a base error class for your library."
def gem(name)
end
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 53cea7d754..ebfaf75b8c 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -28,7 +28,6 @@ module Bundler
@target = SharedHelpers.pwd.join(gem_name)
validate_ext_name if options[:ext]
- validate_error_class if options[:error_class]
end
def run
@@ -57,7 +56,6 @@ module Bundler
:test => options[:test],
:ext => options[:ext],
:exe => options[:exe],
- :error_class => options[:error_class],
:bundler_version => bundler_dependency_version,
:github_username => github_username.empty? ? "[USERNAME]" : github_username
}
@@ -244,18 +242,6 @@ module Bundler
exit 1
end
- def validate_error_class
- error_class = options[:error_class]
-
- if (error = Object.const_get(error_class)) && !(error <= Exception) # rubocop:disable Style/InverseMethods
- Bundler.ui.error "Invalid error class #{error_class}. Please use a class inheriting from Exception."
- exit 1
- end
- rescue NameError
- Bundler.ui.error "Invalid class name #{error_class} for error class. Please provide an Exception subclass."
- exit 1
- end
-
def open_editor(editor, file)
thor.run(%(#{editor} "#{file}"))
end
diff --git a/lib/bundler/templates/newgem/lib/newgem.rb.tt b/lib/bundler/templates/newgem/lib/newgem.rb.tt
index 457172b403..f441eab5f2 100644
--- a/lib/bundler/templates/newgem/lib/newgem.rb.tt
+++ b/lib/bundler/templates/newgem/lib/newgem.rb.tt
@@ -6,11 +6,7 @@ require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
<%- config[:constant_array].each_with_index do |c, i| -%>
<%= " " * i %>module <%= c %>
<%- end -%>
-<%- if config[:error_class] -%>
-<%= " " * config[:constant_array].size %>class Error < <%= config[:error_class] %>
-<%= " " * config[:constant_array].size %> # Base class for your errors
-<%= " " * config[:constant_array].size %>end
-<%- 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 cfc8284585..f4642787cb 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -554,38 +554,6 @@ RSpec.describe "bundle gem" do
end
end
- context "--error-class flag set" do
- context "with valid error class name" do
- it "generates a gem skeleton with error subclassing given base class" do
- execute_bundle_gem("test_gem", "--error-class RuntimeError")
- expect(bundled_app("test_gem/lib/test_gem.rb").read).to include("< RuntimeError")
- end
- end
-
- context "with non-error class name" do
- it "fails to generate a gem skeleton" do
- expect do
- execute_bundle_gem("test_gem", "--error-class Enumerable")
- end.to raise_error(RuntimeError, /Invalid error class/)
- end
- end
-
- context "with invalid class name" do
- it "fails to generate a gem skeleton" do
- expect do
- execute_bundle_gem("test_gem", "--error-class qpwoeiryt")
- end.to raise_error(RuntimeError, /Invalid class name/)
- end
- end
- end
-
- context "--no-error-class flag set" do
- it "generates a gem skeleton without error subclass" do
- execute_bundle_gem("test_gem", "--no-error-class")
- expect(bundled_app("test_gem/lib/test_gem.rb").read).to_not include("class Error")
- end
- end
-
context "gem naming with dashed" do
let(:gem_name) { "test-gem" }