jsonapi-rb / jsonapi-rspec

RSpec matchers for JSON:API spec
https://rubygems.org/gems/jsonapi-rspec
MIT License
123 stars 24 forks source link

Allow matchers in expected value in with_data chain #32

Open wildfiler opened 2 years ago

wildfiler commented 2 years ago

What is the current behavior?

In have_relationship.with_data you can pass only actual values, it doesn't work with other matches.

What is the new behavior?

Add support for matches to have_relationship.with_data to allow write more customizable expectations, like expecting all records to have some type, or expecting to have record with some id, ignoring others:

doc = {
  'relationships' => {
    'comments' => {
      'data' => [
        { 'id' => '1', 'type' => 'comment' },
        { 'id' => '2', 'type' => 'comment' }
      ]
    }
  }
}

expect(doc).to have_relationship('comments').with_data(all(have_type('comment')))
expect(doc).to have_relationship('comments').with_data(include(have_id('1')))

Checklist

Please make sure the following requirements are complete: