Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on invalid body #427

Merged
merged 2 commits into from
Nov 2, 2014
Merged

Conversation

markjlorenz
Copy link

It's pretty common for me to try to give a Hash to #to_return(body: ). This results in errors like:

     JSON::ParserError:
       757: unexpected token at '{:one=>"two"}'

It would save debugging time if WebMock raised an error, instead of accepting the Hash. This PR implements that error.

@bblimke
Copy link
Owner

bblimke commented Nov 2, 2014

Perhaps Hash should be supported? How should it be encoded though? JSON, XML?

@markjlorenz
Copy link
Author

That was my original intent when I sat down to write this PR.

I would want the Hash to be converted to what ever the Accept header is set to.

For JSON, it's pretty straight forward, for XML it could get complicated (e.g. namespaces). I decided this was too much responsibility for WebMock to take on.

Do you have a straightforward implementation in mind?

@bblimke
Copy link
Owner

bblimke commented Nov 2, 2014

Indeed, it may be too much for WebMock.

Why do you allow Array to be passed as body?

@markjlorenz
Copy link
Author

There was a test that failed when I didn't :-)

It looks like that's how you specify a chunked response in WebMock.

@bblimke
Copy link
Owner

bblimke commented Nov 2, 2014

Indeed, I forgot about it. WebMock really deserves proper documentation instead of one big readme ;)

bblimke added a commit that referenced this pull request Nov 2, 2014
@bblimke bblimke merged commit 94d71c7 into bblimke:master Nov 2, 2014
@markjlorenz
Copy link
Author

I can make a rough draft of some updated in-depth documentation.

Did you have a specific framework (like Rspec's relish) in mind?

@bblimke
Copy link
Owner

bblimke commented Nov 2, 2014

I like the minimalistic way http://markevans.github.io/dragonfly/ is done, although I'm not sure what is used there.

To be honest, anything will be better than current docs, so I'd be happy with any framework :)

nahi pushed a commit to treasure-data/td-client-ruby that referenced this pull request Dec 2, 2014
WebMock fixed argument handling of 'to_return'. Update td-client-ruby's
spec to follow the change. The detail is here; bblimke/webmock#427
dkerwin added a commit to gini/gini-api-ruby that referenced this pull request Jan 8, 2015
benkoshy added a commit to benkoshy/webmock that referenced this pull request Nov 5, 2020
Why this PR?

Right now, users might be confused as to why a hash cannot be accepted
as a response body? See Issue bblimke#449 on Github as well as bblimke#427.

This seems to have caused considerable consternation
to API users - with some spending many frustrated hours searching for a
solution. Perhaps it can be solved with a more helpful exception
message? This PR hopes to remedy this apparent shortcoming. Perhaps
I shall remedy it with an update to the documentation as well.

I submit it with the utmost respect to the maintainers and community.

Thank you for your efforts, and for reviewing.

Ben
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants