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

Json-ify any non-string object in #to_return_json #1012

Merged

Conversation

inkstak
Copy link
Contributor

@inkstak inkstak commented Dec 12, 2022

When using to_return_json, it allows to pass an Array body.
By extension, it'll convert any non-string object passed to :body parameter to json.

stub_request(...).to_return_json(body: [{abc: "def" }])
stub_request(...).to_return_json(body: Record.find(1))

@jasonkarns
Copy link

Love this!

Any chance it can be extended to accept procs also? It's a jarring inconsistency that to_return can accept a body: -> {} lambda but to_return_json doesn't.

Rather disappointing that in order for the stub to trigger any side effects, we have to drop out of to_return_json and lose the header/body niceties.

@inkstak inkstak force-pushed the feature-to_return_json_accepts_array_body branch from 54a634e to cc4644f Compare May 19, 2023 11:07
@inkstak
Copy link
Contributor Author

inkstak commented May 19, 2023

Added to the PR:

stub_request(...).to_return_json(body: ->{ Record.find(1) })

@bblimke
Copy link
Owner

bblimke commented Aug 19, 2023

Great improvement. Thank you @inkstak .

@jasonkarns thank you for suggesting support for procs.

@bblimke bblimke merged commit d933001 into bblimke:master Aug 19, 2023
@inkstak
Copy link
Contributor Author

inkstak commented Aug 20, 2023

@bblimke Thank you for maintaining this awesome gem !

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

3 participants