I'm trying to verify that a method gets called twice with specific values, but I can't seem to verify both calls, just the first. I have verified that the method is called twice and that the values are correct, but I'm not sure how to write the cedar spec.
Here is what I have:
it(@"should call sleep with time intervals of 0 and 5", ^{
// subject is a spied on object
subject should have_received(@selector(someMethod:)).with(0); // Passes
subject should have_received(@selector(someMethod:)).with(5); // Fails
}
The error I'm getting is this:
Expected <MyObject> to have received message <someMethod:>, with arguments: <5> but received messages:
someMethod:<0>
someMethod:<5>
I think the problem you're actually running into is that Cedar is very picky about types. For example, assuming
someMethod:
takes an NSTimeInterval, this is how you would fix your problem. (If it's not NSTimeInterval, replace it for the actual type).When you call
[subject someMethod:5]
the integer 5 is implicitly cast from an integer to an NSTimeInterval, but the same thing doesn't happen when you give the integer 5 to Cedar'swith()
, so Cedar does not treat them as identical. Your first assertion passed only because it's 0. If you were to change it to a non-zero value, you'd find that it fails just like the second assertion does.