assign_to_matcher incorrectly passes with nil values #124

james2m opened this Issue Aug 16, 2010 · 1 comment


None yet

2 participants


assign_to_match assumes .with { 'value' } hasn't been set if the value evaluates to nil which can cause tests which should fail to appear to pass.

Quick fix;

    def with(expected_value = nil, &block)
      @value_expected = true         # <== ensure with has been assigned
      @expected_value = expected_value
      @expectation_block = block

    def equal_to_expected_value?
     return true unless @value_expected    # <== Check with was assigned
      if @expected_value == assigned_value

I was going to submit a patch but I can't get the tests to run.

thoughtbot, inc. member

Thanks for the patch. This is committed and will be fixed in the next release.

@showaltb showaltb pushed a commit to showaltb/shoulda that referenced this issue Aug 3, 2011
@jferris jferris Treat missing/nil controller assigns differently; fixed gh-124 (based…
… on patch from James McCarthy)
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment