rspec / rspec-expectations

Provides a readable API to express expected outcomes of a code example
https://rspec.info
MIT License
1.26k stars 397 forks source link

"NotImplementedError: `expect { }.not_to change { }.by()` is not supported" - would be nice to improve #1433

Open loqimean opened 11 months ago

loqimean commented 11 months ago

Hi, there is an error when you add .by(..) to your expect {}.not_to change(some, :attr), like expect {}.not_to change(some, :attr).by(1) that says "NotImplementedError: expect { }.not_to change { }.by() is not supported" and.., it's really not good, because you see the first things that say "You can use change matcher with the block" but you miss that there is a problem 'cause you forget to delete or just added .by(..) to your matcher. My solution: To change the error message like to this: Hey, you cannot use '.by(1)' in your <code> matcher, it is not supported, delete it or change matcher, please. *Would be fun if the message can be like this, please ^-^

pirj commented 11 months ago

Would you harvest the codebase for similar messages, and send a PR to make them more consistent?

JonRowe commented 11 months ago

The error comes from here https://github.com/rspec/rspec-expectations/blob/main/lib/rspec/matchers/built_in/change.rb#L150

        def does_not_match?(_event_proc)
          raise NotImplementedError, "`expect { }.not_to change " \
            "{ }.#{@relativity}()` is not supported"
        end

This could be changed to "{ }.#{@relativity}() is not supported, remove #{@relativity} or refactor your expression.` or similar...