<commit_before>Feature: include_json matcher

  Background:
    Given a file "spec/spec_helper.rb" with:
          """ruby
          require "rspec/json_expectations"
          """
      And a local "SIMPLE_JSON" with:
          """json
          {
            "id": 25,
            "email": "<EMAIL>",
            "name": "John"
          }
          """
      And a local "BIG_JSON" with:
          """json
          {
            "id": 25,
            "email": "<EMAIL>",
            "password_hash": "<PASSWORD>",
            "name": "John",
            "profile_id": 39,
            "role": "admin"
          }
          """

  Scenario: Simple usage example
    Given a file "spec/simple_example_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{SIMPLE_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 25,
                email: "<EMAIL>",
                name: "John"
              )
            end
          end
          """
     When I run "rspec spec/simple_example_spec.rb"
     Then I see:
          """
          1 example, 0 failures
          """

  Scenario: Simple usage with failure
    Given a file "spec/simple_with_fail_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{SIMPLE_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 37,
                email: "<EMAIL>",
                name: "Smith"
              )
            end
          end
          """
     When I run "rspec spec/simple_with_fail_spec.rb"
     Then I see:
          """
          1 example, 1 failure
          """
      And I see:
          """
                              expected: 37
                                   got: 25
          """
      And I see:
          """
                              expected: "Smith"
                                   got: "John"
          """
      And I see:
          """ruby
          # ./spec/simple_with_fail_spec.rb
          """

  Scenario: Excessive fields on subject json are ignored
    Given a file "spec/excessive_fields_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{BIG_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 25,
                name: "John",<commit_msg>Added description for include_json matcher<commit_after>Feature: include_json matcher

  As a developer extensively testing my APIs with RSpec
  I want to have a suitable tool to test my API responses
  And I want to use simple ruby hashes to describe the parts of response
  For that I need a custom matcher

  Background:
    Given a file "spec/spec_helper.rb" with:
          """ruby
          require "rspec/json_expectations"
          """
      And a local "SIMPLE_JSON" with:
          """json
          {
            "id": 25,
            "email": "<EMAIL>",
            "name": "John"
          }
          """
      And a local "BIG_JSON" with:
          """json
          {
            "id": 25,
            "email": "<EMAIL>",
            "password_hash": "<PASSWORD>",
            "name": "John",
            "profile_id": 39,
            "role": "admin"
          }
          """

  Scenario: Expecting json string to include simple json
    Given a file "spec/simple_example_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{SIMPLE_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 25,
                email: "<EMAIL>",
                name: "John"
              )
            end
          end
          """
     When I run "rspec spec/simple_example_spec.rb"
     Then I see:
          """
          1 example, 0 failures
          """

  Scenario: Expecting wrong json string to include simple json
    Given a file "spec/simple_with_fail_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{SIMPLE_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 37,
                email: "<EMAIL>",
                name: "Smith"
              )
            end
          end
          """
     When I run "rspec spec/simple_with_fail_spec.rb"
     Then I see:
          """
          1 example, 1 failure
          """
      And I see:
          """
                              expected: 37
                                   got: 25
          """
      And I see:
          """
                              expected: "Smith"
                                   got: "John"
          """
      And I see:
          """ruby
          # ./spec/simple_with_fail_spec.rb
          """

  Scenario: Expecting json response with excessive fields to include 'smaller' json
    Given a file "spec/excessive_fields_spec.rb" with:
          """ruby
          require "spec_helper"

          RSpec.describe "A json response" do
            subject { '%{BIG_JSON}' }

            it "has basic info about user" do
              expect(subject).to include_json(
                id: 25,
                name: "John",
{'fraction_non_alphanumeric': 0.09732272069464544, 'fraction_numerical': 0.00723589001447178, 'mean_word_length': 1.1897029702970296, 'pattern_counts': {'":': 18, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5323914', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1432, 'n_words': 444}