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

How to use captures with Rspec? #23

Open
petrsigut opened this issue Dec 11, 2013 · 3 comments
Open

How to use captures with Rspec? #23

petrsigut opened this issue Dec 11, 2013 · 3 comments

Comments

@petrsigut
Copy link

Hi guys,

json_expressions are really cool! Thanks.

But I am unable to find out how to use "captures" with Rspec, is it possible?

The example shows how to use it with MiniTest:

matcher = assert_json_match pattern, server_response.body # Returns the Matcher object
You can use the captured values for other purposes
assert matcher.captures[:user_id] > 0

But In Rspec, if I use it like this:

matcher = response.body.should match_json_expression(pattern)

but matcher is "true"...

I also tried to get match_json_expression(pattern), this is JsonExpressions::RSpec::Matchers::MatchJsonExpression, but does not contain "captures" either.

So I included the require 'json_expressions/minitest' to be able to use the minitest

matcher = assert_json_match pattern, response.body

But is that right approach?

Thank you very much,
Petr

@martinos
Copy link

martinos commented Aug 3, 2016

Is this solved? It seems that it would be really useful with rspec.

@petrsigut
Copy link
Author

I am not longer on the project which was using it, so I don't know:( Sorry

@callahat
Copy link

callahat commented Aug 7, 2017

If you're using the expect(response.body).to match_json_expression(pattern) syntax, it seems that pattern is modified with the captures. Ie, you can access it using pattern.captures[:user_id].

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

No branches or pull requests

3 participants