Skip to content

Commit

Permalink
add better error message for invalid types (Fixes #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethpollack committed Jul 3, 2015
1 parent 51a15ba commit e2da6e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/airborne/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def is_nil_optional_hash?(expectations, hash)
def expect_type(expected_type, value_class, prop_name = nil)
insert = prop_name.nil? ? "" : "#{prop_name} to be of type"
msg = "Expected #{insert} #{expected_type}\n got #{value_class} instead"
raise ExpectationError, "Expected type #{expected_type}\nis an invalid type" if @mapper[expected_type].nil?
expect(@mapper[expected_type].include?(value_class)).to eq(true), msg
end

Expand Down
6 changes: 6 additions & 0 deletions spec/airborne/expectations/expect_json_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@
expect_json_types({name: :string, age: :int, address: :null})
end

it 'Should throw bad type error' do
mock_get('simple_get')
get '/simple_get'
expect { expect_json_types(name: :foo) }.to raise_error(Airborne::ExpectationError, "Expected type foo\nis an invalid type")
end

end

0 comments on commit e2da6e9

Please sign in to comment.