Skip to content

How to use captures with Rspec? #23

@petrsigut

Description

@petrsigut

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions