Sha256: 8a82ab7c35333f6ce1d800a57dc3aecf3b30c5e2a2af158bb52eed858897bd14

Contents?: true

Size: 773 Bytes

Versions: 11

Compression:

Stored size: 773 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :be_a_json_object do
  @properties = []

  match do |object|
    expect(object).to have_key 'type'
    expect(object).to have_key 'properties'
    expect(object['type']).to eq 'object'

    if @properties.present?
      @properties.each do |property|
        expect(object['properties']).to have_key property
      end
    end

    true
  end

  chain :with_properties do |*properties|
    @properties |= properties
  end

  chain :with_property do |property|
    @properties << property
  end

  failure_message_for_should do |object|
    "expected that #{object.try(:to_hash) || object} to be a json object".tap do |message|
      message << " with properties #{@properties}" if @properties.present?
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lurker-1.0.0 spec/support/matchers/json_object.rb
lurker-0.6.12 spec/support/matchers/json_object.rb
lurker-0.6.11 spec/support/matchers/json_object.rb
lurker-0.6.10 spec/support/matchers/json_object.rb
lurker-0.6.9 spec/support/matchers/json_object.rb
lurker-0.6.8 spec/support/matchers/json_object.rb
lurker-0.6.7 spec/support/matchers/json_object.rb
lurker-0.6.6 spec/support/matchers/json_object.rb
lurker-0.6.5 spec/support/matchers/json_object.rb
lurker-0.6.4 spec/support/matchers/json_object.rb
lurker-0.6.3 spec/support/matchers/json_object.rb