Sha256: bb43bf91a11521d7ca786ec7a4ba2c64176249a7700917db171ad4776cd5010b

Contents?: true

Size: 622 Bytes

Versions: 4

Compression:

Stored size: 622 Bytes

Contents

# frozen_string_literal: true

require "json"

RSpec::Matchers.define :contain_json do
  match do
    @sub_json = expected
    @filename = actual

    @filepath = File.join(project_path, @filename)
    @json = JSON.parse(IO.read(@filepath), symbolize_names: true)

    subhash?(@sub_json, @json)
  end

  failure_message do
    "in #{@filename}, expected to find\n#{@sub_json.inspect}\n" \
      "in\n#{@json.inspect}"
  end

  private

  def subhash?(inner, outer)
    if inner.is_a?(Hash) && outer.is_a?(Hash)
      inner.all? { |key, value| subhash?(value, outer[key]) }
    else
      inner == outer
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
suspenders-1.55.1 spec/support/contain_json_matcher.rb
suspenders-1.55.0 spec/support/contain_json_matcher.rb
suspenders-1.54.1 spec/support/contain_json_matcher.rb
suspenders-1.54.0 spec/support/contain_json_matcher.rb