diff --git a/lib/multi_json.rb b/lib/multi_json.rb index ca1e442d..9b0540a4 100644 --- a/lib/multi_json.rb +++ b/lib/multi_json.rb @@ -98,8 +98,10 @@ def load_adapter(new_adapter) when Class, Module new_adapter else - raise "Did not recognize your adapter specification. Please specify either a symbol or a class." + raise NameError end + rescue NameError, ::LoadError + raise ArgumentError, 'Did not recognize your adapter specification.' end # Decode a JSON string into Ruby. diff --git a/spec/multi_json_spec.rb b/spec/multi_json_spec.rb index 02310a2b..00e1cdd0 100644 --- a/spec/multi_json_spec.rb +++ b/spec/multi_json_spec.rb @@ -74,11 +74,15 @@ end it 'is settable via a module' do - adapter = Module.new + adapter = Module.new MultiJson.use adapter expect(MultiJson.adapter).to eq adapter end + it 'throws ArgumentError on bad input' do + expect{ MultiJson.use 'bad adapter' }.to raise_error(ArgumentError) + end + context 'using one-shot parser' do before do MultiJson::Adapters::JsonPure.should_receive(:dump).once.and_return('dump_something') @@ -159,4 +163,4 @@ it_behaves_like 'JSON-like adapter', adapter end end -end +end \ No newline at end of file