Conversation
11cd4a9 to
072affe
Compare
072affe to
cb04fd5
Compare
|
This is neat, but it is not safe. I tested this cop on one of our services, and found that it auto-corrected some longer integration tests doing something like this expect(list.length).to eq(4)
expect(Api.call.response.code).to eq(200)
Foo.update(whatever)
expect(list.length).to eq(4)
expect(Api.call.response.code).to eq(200)into expect(list).to have_attributes(
length: 4,
length: 4
)
expect(Api.call.response).to have_attributes(
code: 200,
code: 200
)
Foo.update(whatever)This is obviously pseudo-code, but if necessary I can produce a more realistic snipped. |
|
Thank you. I also was playing with a real code base and found out the case when there could be two expectations on the same attribute, generating a duplicated key. While this could be corrected to a combined matcher like: there is the case of an action between the expectations (which is probably what you were pointing out) that would change the result, so in a sense the corrected code would be which could never pass - it is expected to have different value in different points of time. |
Yes, this is what I was trying to point out. So as you also mention, to work safely, the cop can unfortunately only point out expectations right after each other, since it will be hard/impossible to detect if code in between the expectations could alter the result. |
Fixes #1057
Before submitting the PR make sure the following are checked:
master(if not - rebase it).CHANGELOG.mdif the new code introduces user-observable changes.bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml.Enabled: pendinginconfig/default.yml.Enabled: truein.rubocop.yml.VersionAdded: "<<next>>"indefault/config.yml.