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

Improve handling of object-typed nil values during argument matching #226

Merged

Conversation

briancroom
Copy link
Contributor

The existing tests around the usage of nil generally use a simple nil literal, which seems to be treated as type int by the compiler. I've fixed behavior and crashes around the usage of nil which is typed as id.

@idoru
Copy link
Contributor

idoru commented Apr 19, 2014

f20cdc2 is tricky. I can understand the motivation for the stubbed method argument to match, but this also impacts the equals matcher in test assertions (See #100) for some history. We may have to do some transformation of the nil argument passed to .with() instead.

@briancroom
Copy link
Contributor Author

Hm I see. Could elaborate a bit on the motivation for reverting #100, perhaps with an example? I'd like to add some tests to specify the aspects of the equals matcher that we want to preserve before taking another go at this.

@jeffh
Copy link
Contributor

jeffh commented Apr 20, 2014

The reason for reverting #100 is to not have to constantly check for nil when writing expectations. Say comparing this:

    Items.firstObject should equal(array.lastObject)

This expectation can pass in a case that can be more surprising since both can return nils. It's more common in tests to expect non-nil than nil values.

Sent from Mailbox for iPad

On Sat, Apr 19, 2014 at 5:28 PM, Brian Croom notifications@github.com
wrote:

Hm I see. Could elaborate a bit on the motivation for reverting #100, perhaps with an example? I'd like to add some tests to specify the aspects of the equals matcher that we want to preserve before taking another go at this.

Reply to this email directly or view it on GitHub:
#226 (comment)

@briancroom
Copy link
Contributor Author

Got it. I've been doing some additional work on this, but I did have one question. Given the same context as above, should it pass or fail with the negative matcher?

items.firstObject should_not equal(array.lastObject)

I'm thinking it should fail based on the same reasoning, but that does not appear to be the current behavior.

@jeffh
Copy link
Contributor

jeffh commented Apr 28, 2014

I'm thinking that it should, but that fix might introduce unintended regressions at this point. We'll need to discuss this more for that case.—
Sent from my iPhone

On Wed, Apr 23, 2014 at 8:45 AM, Brian Croom notifications@github.com
wrote:

Got it. I've been doing some additional work on this, but I did have one question. Given the same context as above, should it pass or fail with the negative matcher?
items.firstObject should_not equal(array.lastObject)

I'm thinking it should fail based on the same reasoning, but that does not appear to be the current behavior.

Reply to this email directly or view it on GitHub:
#226 (comment)

@briancroom
Copy link
Contributor Author

I've pushed out some more work that corrects the behavior of compare_equal with nil, while allowing nil argument matches, as well as improving nil handling in several other places.

@idoru
Copy link
Contributor

idoru commented May 2, 2014

This behavior looks good now. I'm not sure the series of commits to arrive at this behavior should be on master, though. What do you think about squashing them?

…ching method arguments

- Properly match methods invocations which include a `nil` argument [#63351266]
- Fix stringifiers for NSNumber and for generic objects to correctly handle nil values
- Fix the compare_equal matcher for two NSNumber's to not blow up if the expectedValue is nil [#69580148]
- Equal matcher fails explicitly when used with nil
  - In this situation, presumably the value passed in was intended to not be nil, hence it is treated as a failure
  - The be_nil matcher is mentioned in case checking for nil was the actual intention
- be_nil matcher can be used with block values [#42698619]
@idoru
Copy link
Contributor

idoru commented May 6, 2014

Thanks for tidying up!

idoru added a commit that referenced this pull request May 6, 2014
…er-with-nil-as-id

Improve handling of object-typed nil values during argument matching
@idoru idoru merged commit f8d2cbb into cedarbdd:master May 6, 2014
@briancroom briancroom deleted the fix-invocation-matcher-with-nil-as-id branch May 8, 2014 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants