Code Monkey home page Code Monkey logo

Comments (10)

lukeredpath avatar lukeredpath commented on July 2, 2024

If you are expecting myBar.foo to be nil, could you not use:

[myBar.foo shouldNotBeNil];

from kiwi.

joshuatbrown avatar joshuatbrown commented on July 2, 2024

If I were expecting it to be nil, you're right - I could do it that way. However, I'd like to make the weak assertion that it's not equal to baz - it can be nil or not nil. As long as it's not equal to baz, I'm happy.

from kiwi.

lukeredpath avatar lukeredpath commented on July 2, 2024

I haven't tested this so it might not work out of the box, but how about:

id foo = myBar.foo;
[[theObject(&foo) shouldNot] equal:bar];

from kiwi.

lukeredpath avatar lukeredpath commented on July 2, 2024

Another alternative is to use theReturnValueOfBlock:

[[theReturnValueOfBlock(^{ return myBar.foo; }) shouldNot] equal:bar];

from kiwi.

joshuatbrown avatar joshuatbrown commented on July 2, 2024

I could probably use one of your suggestions, but I like how clean Kiwi is and I'd like to be able to keep my specs clean. I can use one of these temporarily, but I'd really like to be able to keep my code as originally written in the issue.

from kiwi.

lukeredpath avatar lukeredpath commented on July 2, 2024

The problem with your example is it's simply not possible to send a message to nil; I can't think of a way around it other than boxing the variable.

from kiwi.

joshuatbrown avatar joshuatbrown commented on July 2, 2024

Good point. That brings up another question, then - how does [myBar.foo shouldNotBeNil]; work? If foo is nil, how can it fail? Or how does shouldBeNil work?

from kiwi.

allending avatar allending commented on July 2, 2024

shouldNotBeNil isn't a message, it is a macro that expands to a fragment that both sends a message, and creates an object that is an argument to the message.

Perhaps this is a simpler way to think about it:

[bobby shouldNotBeNil] expands to [bob shakeHandWith:[[alice alloc] init]]. shakeHandWith: would be implemented simply as "[visitor acknowledgeHandshakeBy:self]". If alice does not receive a handshake by the time the test ends, we know the message got sent to nil!

If you are familiar with the acyclic visitor pattern, this uses a similar mechanic, even though the intent doesn't really have anything to do with the pattern.

Hacky I know, but I felt that the end result made for easier reading.

from kiwi.

joshuatbrown avatar joshuatbrown commented on July 2, 2024

Wow - thanks for the explanation. So you're saying my request is impossible to implement, right? If that's the case, I have no problem with the issue being closed. :)

from kiwi.

allending avatar allending commented on July 2, 2024

Hmm, not impossible, but I would say the alternatives (not complaining about expectations on nil, or new keywords) are not compelling enough.

from kiwi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.