Skip to content

Commit

Permalink
As we always convert NSNulls in invocation parameters back to nil before
Browse files Browse the repository at this point in the history
matching, we need to special case NSNull when creating parameter matchers,
using an IsNil matcher (rather than an isEqual matcher).
  • Loading branch information
lukeredpath committed Jan 10, 2013
1 parent d67518c commit 3fa1af0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Classes/LRMocky/LRAllParametersMatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "LRAllParametersMatcher.h"

#import <OCHamcrest/HCIsEqual.h>
#import <OCHamcrest/HCIsNil.h>
#import <OCHamcrest/HCStringDescription.h>
#import <OCHamcrest/HCDescription.h>

Expand Down Expand Up @@ -69,6 +70,9 @@ - (NSArray *)matchersFrom:(NSArray *)parameters
if ([parameter conformsToProtocol:@protocol(HCMatcher)]) {
[matchers addObject:parameter];
}
else if (parameter == NSNull.null) {
[matchers addObject:HC_nilValue()];
}
else {
[matchers addObject:HC_equalTo(parameter)];
}
Expand Down
14 changes: 13 additions & 1 deletion Tests/Integration/SimpleExpectationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ - (void)testCanExpectMethodCallsWithAnythingAndPassWithGivenNil
assertThat(testCase, passed());
}

- (void)testCanExpectMethodCallsWithNilParameter
- (void)testCanExpectMethodCallsWithNilParameterUsingMatcher
{
[context check:^{
[[expectThat(testObject) receives] doSomethingWithObject:nilValue()];
Expand All @@ -230,6 +230,18 @@ - (void)testCanExpectMethodCallsWithNilParameter
assertThat(testCase, passed());
}

- (void)testCanExpectMethodCallsWithNilParameterUsingNil
{
[context check:^{
[[expectThat(testObject) receives] doSomethingWithObject:nil];
}];

[testObject doSomethingWithObject:nil];
[context assertSatisfied];

assertThat(testCase, passed());
}

//- (void)testCanExpectMethodCallsWithBlockArgumentsWithObjectAndPass;
//{
// [context check:^{
Expand Down

0 comments on commit 3fa1af0

Please sign in to comment.