jsonapi-rspec icon indicating copy to clipboard operation
jsonapi-rspec copied to clipboard

Allow matchers in expected value in with_data chain

Open wildfiler opened this issue 3 years ago • 0 comments

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:

  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • [ ] All automated checks pass (CI/CD)

wildfiler avatar Jan 17 '22 20:01 wildfiler