Sha256: 91053f4d996907d1d077e53ceae33c9f91ed7d4c592002acbbe63d25b2aaebc1

Contents?: true

Size: 696 Bytes

Versions: 11

Compression:

Stored size: 696 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :be_a_json_attribute do
  match do |attribute|
    expect(attribute).to have_key 'type'

    expect(attribute['type']).to eq @type if @type.present?
    expect(attribute['example']).to eq @example if @example.present?

    true
  end

  chain :with_type do |type|
    @type = type
  end

  chain :with_example do |example|
    @example = example
  end

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

Version data entries

11 entries across 11 versions & 1 rubygems

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