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

Fix multiple stubs with different primitive args #101

Merged
merged 1 commit into from
Aug 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Doubles/StubbedMethod.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
for (argument_it = arguments.begin(); argument_it != arguments.end(); ++argument_it) {
Cedar::Doubles::Argument::shared_ptr_t argument_ptr = *argument_it;

if (*argument_ptr == *Arguments::anything) {
if (strcmp(typeid(*argument_ptr).name(), typeid(*Arguments::anything).name()) == 0) {
return true;
}
}
Expand Down
19 changes: 19 additions & 0 deletions Spec/Doubles/CedarDoubleSharedExamples.mm
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ myDouble stub_method("value").and_do(^(NSInvocation *invocation) {
});

describe(@"argument expectations", ^{
context(@"when stubbing the same method multiple times with distinctly different primitive arguments", ^{
__block BOOL firstStubWasCalled, secondStubWasCalled;
beforeEach(^{
firstStubWasCalled = secondStubWasCalled = NO;
myDouble stub_method("incrementByInteger:").with(1).and_do(^(NSInvocation *) {
firstStubWasCalled = YES;
});
myDouble stub_method("incrementByInteger:").with(3).and_do(^(NSInvocation *) {
secondStubWasCalled = YES;
});
});

it(@"should perform the stub action associated with those arguments when invoked with those arguments", ^{
[myDouble incrementByInteger:3];
secondStubWasCalled should be_truthy;
firstStubWasCalled should_not be_truthy;
});
});

context(@"when specified with .with(varargs)", ^{
NSNumber *arg1 = @1;;
NSNumber *arg2 = @2;
Expand Down
1 change: 1 addition & 0 deletions Spec/Doubles/SimpleIncrementer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- (void)increment;
- (void)incrementBy:(size_t)amount;
- (void)incrementByNumber:(NSNumber *)number;
- (void)incrementByInteger:(NSUInteger)number;
- (void)incrementByABit:(size_t)aBit andABitMore:(NSNumber *)aBitMore;
- (void)incrementWithException;
- (void)methodWithBlock:(void(^)())blockArgument;
Expand Down
4 changes: 4 additions & 0 deletions Spec/Doubles/SimpleIncrementer.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ - (void)incrementByNumber:(NSNumber *)number {
self.value += [number intValue];
}

- (void)incrementByInteger:(NSUInteger)integer {
self.value += integer;
}

- (void)incrementByABit:(size_t)aBit andABitMore:(NSNumber *)aBitMore {
self.value += aBit + [aBitMore intValue];
}
Expand Down