Skip to content

Commit

Permalink
Raising ArgumentError on bad adapter input
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Mar 16, 2013
1 parent 7d06012 commit 911a375
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/multi_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.