Skip to content

Commit

Permalink
spec for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanKilleen committed Sep 23, 2018
1 parent 668fe3a commit d7f1b67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/html-proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def parse_json_option(option_name, config)
if config.strip.empty? then
{}
else
JSON.parse(config)
begin
JSON.parse(config)
rescue
raise ArgumentError.new("Option '" + option_name + "' did not contain valid JSON.")
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/html-proofer/parse_json_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
end

it 'Throws an error when the json config is not valid json' do
expect {HTMLProofer.parse_json_option('testName', 'abc')}.to raise_error(ArgumentError, "Option 'testName' did not contain valid JSON.")
end
end

0 comments on commit d7f1b67

Please sign in to comment.