From b7e5788ca4647aa3bc26ead25825d929fa392a09 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sat, 26 Nov 2016 21:12:33 -0800 Subject: [PATCH] Output warning instead of raising an exepection on default type mismatch See https://github.com/erikhuda/thor/pull/435#issuecomment-239373372 --- lib/thor/parser/option.rb | 3 ++- spec/parser/option_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index 654f7adce..fa9bcf9b0 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -127,7 +127,8 @@ def validate_default_type! @default.class.name.downcase.to_sym end - raise ArgumentError, "An option's default must match its type." unless default_type == @type + # TODO: This should raise an ArgumentError in a future version of Thor + warn "Expected #{@type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})" unless default_type == @type end def dasherized? diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 8a7c329b4..7dca4fd6b 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -135,9 +135,9 @@ def option(name, options = {}) end it "raises an error if default is inconsistent with type" do - expect do - option("foo", :type => :numeric, :default => "bar") - end.to raise_error(ArgumentError, "An option's default must match its type.") + expect(capture(:stderr) do + option("foo_bar", :type => :numeric, :default => "baz") + end.chomp).to eq('Expected numeric default value for \'--foo-bar\'; got "baz" (string)') end it "does not raises an error if default is an symbol and type string" do