Sha256: 2ff6c9212be8762486349a4a60f818cd6902f9b9166893ced9f0f5ca122a6b47

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

RSpec::Matchers.define :respond_a_record do |options = {}|
  match do |actual|
    result = JSON.parse(actual.browser.last_response.body, symbolize_names: true)
    result = result[options[:root]] unless options[:root].nil?
    result.instance_of?(Hash)
  end
  description do
    'respond with a record (Hash)'
  end
  failure_message do |actual|
    result = JSON.parse(actual.browser.last_response.body, symbolize_names: true)
    result = result[options[:root]] unless options[:root].nil?
    "expected #{actual} response body would be a record \nneed : Hash, \ngot  : #{result.class}"
  end
  failure_message_when_negated do |actual|
    result = JSON.parse(actual.browser.last_response.body, symbolize_names: true)
    result = result[options[:root]] unless options[:root].nil?
    "expected #{actual} response body would not be a record \nneed : Hash, \ngot  : #{result.class}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-rest-rspec-1.0.0 lib/rack-rest-rspec/matchers/respond_a_record.rb