Permalink
Browse files

Raising ArgumentError on bad adapter input

  • Loading branch information...
rwz committed Mar 12, 2013
1 parent 7d06012 commit 911a3756bdff2cb5ac06497da3fa3e72199cb7ad
Showing with 9 additions and 3 deletions.
  1. +3 −1 lib/multi_json.rb
  2. +6 −2 spec/multi_json_spec.rb
View
@@ -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.
View
@@ -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

0 comments on commit 911a375

Please sign in to comment.