Closed stas closed 4 years ago
@gabrielgasser @mkamensky I will appreciate your feedback on this please. :bowing_man:
@gabrielgasser @mkamensky I will appreciate your feedback on this please. bowing_man
Thanks. As far as I understand, this only allows to check that the list of attributes is precisely the given one. In my case, I would like to make sure it is a subset, but I might not know in advance the full list of attributes.
@mkamensky by default it allows to check only a subset, use .exactly
to make sure all the attributes are included. Please take a look at the test-case:
But what I need is the other inclusion: I wish check that the actual attributes are contained in the ones I provide
@mkamensky I don't understand. Could you explain what exactly is not working here?!
have_jsonapi_attributes(*keys)
behavior is to check that the keys are present in the JSONAPI document
have_jsonapi_attributes(*keys).exactly
behavior is to check that no other except the keys in the list are present in the JSONAPI document
@stas I would like
expect(document['data']).to have_jsonapi_attributes_in(:name, :email)
to pass if the only attribute in the document is :name
, and to fail if the attributes are :name
and :country
. How can I achieve this with your approach?
to pass if the only attribute in the document is
:name
, and to fail if the attributes are:name
and:country
. How can I achieve this with your approach?
@mkamensky this doesn't make sense to me. What are you trying to achieve here?
As a solution, just use have_attribute(:name)
and that's it!
to pass if the only attribute in the document is
:name
, and to fail if the attributes are:name
and:country
. How can I achieve this with your approach?
You can also just use have_jsonapi_attributes(:name).exactly
, this last .exactly
will strictly check that there are no other attributes. See my example above.
The api might return different results, depending on the situation, and I do not wish to analyse precisely what that will. I only want to make sure that it does not return attributes the user is not authorized to see
Anyway, I'm not insisting on including it if you don't find it useful, I can simply keep it for my project
@mkamensky I'm sorry but I'll be closing your requests. We already provided you with a couple of ways to solve your issue. But we can not accept and maintain some very specific matchers based on the users business logic.
Please consider either using have_attribute(:name)
or not_to have_attribute(:YOUR_UNAUTHORIZED_ATTR_NAME)
. Same is true for a list of attributes not_to have_jsonapi_attributes(:YOUR_UNAUTHORIZED_ATTR_NAME1, :YOUR_UNAUTHORIZED_ATTR_NAME2)
What is the current behavior?
There's a conflicting matcher named
have_attributes
, with therspec-expectations
gem.What is the new behavior?
The old matcher is now
have_jsonapi_attributes
.Support for #12 was also added.
Checklist
Please make sure the following requirements are complete: