Sha256: c122efab554db742cefcd30c178b734025e3e5d3bb377f38776248dafb52b3b1

Contents?: true

Size: 713 Bytes

Versions: 4

Compression:

Stored size: 713 Bytes

Contents

RSpec::Matchers.define :have_field do |key, options = {}|
  value = options[:value]

  match do |item|
    item[key.to_s] == value
  end

  description do
    %Q(have the value #{value.to_json} in the field #{key})
  end

  failure_message_for_should do |item|
    %Q(should #{description}, but got #{item})
  end
end

RSpec::Matchers.define :have_fields do |key, options = {}|
  value = options[:value]
  after = options[:after]

  match do |items|
    items.all?{|item| item[key.to_s].send(after) == value }
  end

  description do
    %Q(have the value #{value.to_json} in the field #{key} after #{after})
  end

  failure_message_for_should do |items|
    %Q(should #{description}, but got #{items})
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-api-0.2.0 lib/rspec-api/matchers/fields.rb
rspec-api-0.1.2 lib/rspec-api/matchers/fields.rb
rspec-api-0.1.1 lib/rspec-api/matchers/fields.rb
rspec-api-0.1.0 lib/rspec-api/matchers/fields.rb