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

expecting notifications not working? #163

Open
LightMan opened this issue Aug 24, 2015 · 5 comments
Open

expecting notifications not working? #163

LightMan opened this issue Aug 24, 2015 · 5 comments

Comments

@LightMan
Copy link

Hi, I am just trying to test if a notification is posted...

        expect(^{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationName" object:nil];
        }).to.notify(@"notificationName");

This tests fails with the expected value is nil/null, am I doing something wrong?

I debugged a little and here:
EXPMatcherImplementationBegin(postNotification, (id expected))
expected is always nil, so the block is never executed.

Furthermore it would be nice to check this tweet from AshFurrow talking about object:nil when posting the notification.

@tema-orange
Copy link

Same for me.

@orta
Copy link
Member

orta commented May 18, 2016

you're welcome to take a stab at fixing it?

@LightMan
Copy link
Author

Hi orta, nice to see you again \o/

This issue was opened by me on Aug 24, 2015. It was the first time using expecta, so I thought "I must be doing something wrong", that's why I was not sure if the problem was mine, or the library's.

But If as today this issue still exists I could prepare a example project for more experienced users just to verify this problem, and then gladly try to help fixing it.

@orta
Copy link
Member

orta commented May 18, 2016

👯

It's worth a quick look, I think Ash was right in that tweet: https://gist.github.com/gfontenot/ would probably do a comparison compare, not a string equals, and dictionary equals ( maybe there's no custom isEquals: on NSNotification

@LightMan
Copy link
Author

Nop, I don't see a custom isEquals: on NSNotification, the NSNotifications are filtered to be dispatched to observers with:

/// Returns collection of `NSNotificationReceiver`.
    ///
    /// Will return:
    ///  - elements that property `sender` is `nil` or equals specified parameter `sender`.
    ///  - elements that property `name` is `nil` or equals specified parameter `name`.
    ///
    private func observersMatchingName(_ name:String? = nil, sender: AnyObject? = nil) -> [Iterator.Element] {
        return self.filter { observer in

            let emptyName = observer.name == nil
            let sameName = observer.name == name
            let emptySender = observer.sender == nil
            let sameSender = observer.sender === sender

            return (emptySender || sameSender) && (emptyName || sameName)
        }
    }

I assume that the Objective-C implementation will be similar.

Maybe the problem is in the creation of the matcher. Anyway, I will try to prepare a example project to isolate the issue.

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

No branches or pull requests

3 participants