Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discourage reusing matchers in the same example #116

Closed
wants to merge 1 commit into from

Commits on Feb 3, 2021

  1. Discourage reusing matchers in the same example

    Reusage may have undesired side effects.
    See rspec/rspec-expectations#1287
    
    https://github.com/rspec/rspec-expectations/blob/bd10f0cf3970932781efcd09b5e427877d16a6c2/lib/rspec/matchers/composable.rb#L113
    
        # Historically, a single matcher instance was only checked
        # against a single value. Given that the matcher was only
        # used once, it's been common to memoize some intermediate
        # calculation that is derived from the `actual` value in
        # order to reuse that intermediate result in the failure
        # message.
        #
        # This can cause a problem when using such a matcher as an
        # argument to another matcher in a composed matcher expression,
        # since the matcher instance may be checked against multiple
        # values and produce invalid results due to the memoization.
        #
        # To deal with this, we clone any matchers in `expected` via
        # this method when using `values_match?`, so that any memoization
        # does not "leak" between checks.
    
    rspec/rspec-expectations#518
    pirj committed Feb 3, 2021
    Configuration menu
    Copy the full SHA
    97c8db4 View commit details
    Browse the repository at this point in the history