0f4ab82082
Both `Nokogiri` and `Minitest` have merged the PRs mentioned to integrate support for Ruby's Pattern matching (https://github.com/sparklemotion/nokogiri/pull/2523 and https://github.com/minitest/minitest/pull/936, respectively). This commit adds coverage for those new assertions, and incorporates examples into the documentation for the `response.parsed_body` method. In order to incorporate pattern-matching support for JSON responses, this commit changes the response parser to call `JSON.parse` with [object_class: ActiveSupport::HashWithIndifferentAccess][object_class], since String instances for `Hash` keys are incompatible with Ruby's syntactically pattern matching. For example: ```ruby irb(main):001:0> json = {"key" => "value"} => {"key"=>"value"} irb(main):002:0> json in {key: /value/} => false irb(main):001:0> json = {"key" => "value"} => {"key"=>"value"} irb(main):002:0> json in {"key" => /value/} .../3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/lib/irb/workspace.rb:113:in `eval': (irb):2: syntax error, unexpected terminator, expecting literal content or tSTRING_DBEG or tSTRING_DVAR or tLABEL_END (SyntaxError) json in {"key" => /value/} ^ .../ruby/3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.7.4/exe/irb:9:in `<top (required)>' .../ruby/3.2.0/bin/irb:25:in `load' .../ruby/3.2.0/bin/irb:25:in `<main>' ``` When the Hash maps String keys to Symbol keys, it's able to be pattern matched: ```ruby irb(main):005:0> json = {"key" => "value"}.with_indifferent_access => {"key"=>"value"} irb(main):006:0> json in {key: /value/} => true ``` [object_class]: https://docs.ruby-lang.org/en/3.2/JSON.html#module-JSON-label-Parsing+Options |
||
---|---|---|
.. | ||
request | ||
routing | ||
session | ||
system_testing | ||
test_response_test | ||
actionable_exceptions_test.rb | ||
assume_ssl_test.rb | ||
callbacks_test.rb | ||
content_disposition_test.rb | ||
content_security_policy_test.rb | ||
cookies_test.rb | ||
debug_exceptions_test.rb | ||
debug_locks_test.rb | ||
exception_wrapper_test.rb | ||
executor_test.rb | ||
header_test.rb | ||
host_authorization_test.rb | ||
live_response_test.rb | ||
mapper_test.rb | ||
middleware_stack_test.rb | ||
mime_type_test.rb | ||
mount_test.rb | ||
permissions_policy_test.rb | ||
prefix_generation_test.rb | ||
rack_cache_test.rb | ||
reloader_test.rb | ||
request_id_test.rb | ||
request_test.rb | ||
response_test.rb | ||
routing_assertions_test.rb | ||
routing_test.rb | ||
runner_test.rb | ||
server_timing_test.rb | ||
show_exceptions_test.rb | ||
ssl_test.rb | ||
static_test.rb | ||
test_request_test.rb | ||
test_response_test.rb | ||
uploaded_file_test.rb | ||
url_generation_test.rb |