-
-
Save zernel/5065942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mbp:godfrey json_expressions [master] $ irb -Ilib | |
>> require 'json_expressions/matcher' | |
=> true | |
>> m = JsonExpressions::Matcher.new({a: :capture_me}) | |
=> {:a=>:capture_me} | |
>> require 'json' | |
=> true | |
>> m =~ JSON.parse('{"a": 123}') | |
=> true | |
>> m.captures | |
=> {:capture_me=>123} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For RSpec... | |
response.body # => '{"a": 123}' | |
matcher = JsonExpressions::Matcher.new({a: :capture_me}) | |
response.body.should match_json_expression(matcher) | |
# If we reaches here it means the response matched our pattern, so we can use the captured value | |
matcher.captures[:capture_me] # => 123 | |
# Ideally, I'd like to be able to just do this, but I wouldn't know how to make it work. Pull requests welcomed | |
matcher = response.body.should match_json_expression({a: :capture_me}) | |
matcher.captures[:capture_me] # => 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment