assign_to_matcher incorrectly passes with nil values #124

Closed
james2m opened this Issue Aug 16, 2010 · 1 comment

Projects

None yet

2 participants

@james2m

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
      self
    end

    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.

@jferris
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)
b0692c3
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment