You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a matcher is nested within the have_attributes matcher, then the attribute for the nested matcher(s) will show up in the error diff as failed whenever any attribute in the parent matcher fails validation. This makes the actual failed condition more difficult to determine, especially when multiple nested matchers are used in a spec.
Your environment
Ruby version: 2.4.1p111
rspec-expectations version: 3.6.0, 3.7.0
Steps to reproduce
Run the following spec and observe the output for the failing test shows the nested matchers as failed when in fact only the role attribute has an error (see output in Actual Behavior below):
RSpec.describe'have_attributes nested messages'dosubjectdodouble(child: double(name: 'Elsa'),name: 'Agnarr',role: 'King',things: ['Staff','Crown'])endit'only prints failing attributes on failure'doexpect(subject).tohave_attributes(name: 'Agnarr',role: 'Queen',# Only this field actually fails validationchild: have_attributes(name: 'Elsa'),things: match_array(['Staff','Crown']))endit'passes'doexpect(subject).tohave_attributes(name: 'Agnarr',role: 'King',child: have_attributes(name: 'Elsa'),things: match_array(['Staff','Crown']))endend
Expected behavior
Only the failed attributes should be displayed in the error diff. Nested have_attributes or other matchers should not be displayed if they pass validation.
The output for the example test should look something like:
The text was updated successfully, but these errors were encountered:
tmertens
changed the title
Nested have_attributes matchers are displayed in error diff when any attribute fails validation
Nested matchers are displayed in have_attributes error diff when any attribute fails validation
Jul 16, 2018
Thanks for reporting this. See #1064 for a complete explanation, but the TL;DR is that this is a known issue since RSpec uses a textual differ. Any time the textual representation of two objects is different, it gets highlighted as a difference in the output, even if the objects match.
@benoittgt has started prototyping a new differ that should eventually solve these problems.
Closing since there's nothing actionable for us to do at this time (outside of the work @benoittgt is already doing).
Subject of the issue
When a matcher is nested within the
have_attributes
matcher, then the attribute for the nested matcher(s) will show up in the error diff as failed whenever any attribute in the parent matcher fails validation. This makes the actual failed condition more difficult to determine, especially when multiple nested matchers are used in a spec.Your environment
Steps to reproduce
Run the following spec and observe the output for the failing test shows the nested matchers as failed when in fact only the
role
attribute has an error (see output in Actual Behavior below):Expected behavior
Only the failed attributes should be displayed in the error diff. Nested
have_attributes
or other matchers should not be displayed if they pass validation.The output for the example test should look something like:
Actual behavior
Non-failed attributes are displayed in the error diff even if they would pass validation.
The output of the test above looks like:
The text was updated successfully, but these errors were encountered: