diff --git a/lib/api.rb b/lib/api.rb index 848b806..a4d97c6 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -57,6 +57,6 @@ not_found do halt_with_message 404, 'Not found' end -error Quote::Invalid do +error ArgumentError do halt_with_message 422, env['sinatra.error'].message.capitalize end diff --git a/lib/quote.rb b/lib/quote.rb index 229393d..6d35c56 100644 --- a/lib/quote.rb +++ b/lib/quote.rb @@ -4,8 +4,6 @@ require 'currency' class Quote include Virtus.value_object - NotValid = Class.new(ArgumentError) - DEFAULT_BASE = 'EUR' values do @@ -32,7 +30,7 @@ class Quote def date=(date) current_date = Currency.current_date_before(date) - fail NotValid, 'Date too old' unless current_date + fail ArgumentError, 'Date too old' unless current_date super current_date end @@ -54,7 +52,7 @@ class Quote def find_rebased_rates rates = find_default_rates denominator = rates.update(DEFAULT_BASE => 1.0).delete(base) - fail NotValid, 'Invalid base' unless denominator + fail ArgumentError, 'Invalid base' unless denominator rates.each do |iso_code, rate| rates[iso_code] = round_rate(rate / denominator) end diff --git a/spec/quote_spec.rb b/spec/quote_spec.rb index 6834228..d0205f2 100644 --- a/spec/quote_spec.rb +++ b/spec/quote_spec.rb @@ -54,9 +54,7 @@ describe Quote do let(:quote) { Quote.new(base: 'FOO') } it 'fails' do - stub_rates 'USD' => 1.25 do |quote| - proc { quote.to_h }.must_raise Quote::NotValid - end + proc { quote.to_h }.must_raise ArgumentError end end @@ -65,7 +63,7 @@ describe Quote do it 'fails' do Currency.stub :current_date_before, nil do - proc { quote }.must_raise Quote::NotValid + proc { quote }.must_raise ArgumentError end end end