Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 129 lines (111 sloc) 5.39 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//

#import "Kiwi.h"
#import "KiwiTestConfiguration.h"
#import "TestClasses.h"

#if KW_TESTS_ENABLED

@interface KWReceiveMatcherTest : SenTestCase

@end

@implementation KWReceiveMatcherTest

- (void)testItShouldHaveTheRightMatcherStrings {
    id matcherStrings = [KWReceiveMatcher matcherStrings];
    id expectedStrings = [NSArray arrayWithObjects:@"receive:",
                                                   @"receive:withCount:",
                                                   @"receive:withCountAtLeast:",
                                                   @"receive:withCountAtMost:",
                                                   @"receive:andReturn:",
                                                   @"receive:andReturn:withCount:",
                                                   @"receive:andReturn:withCountAtLeast:",
                                                   @"receive:andReturn:withCountAtMost:",
                                                   @"receiveMessagePattern:countType:count:",
                                                   @"receiveMessagePattern:andReturn:countType:count:", nil];
    STAssertEqualObjects([matcherStrings sortedArrayUsingSelector:@selector(compare:)],
                         [expectedStrings sortedArrayUsingSelector:@selector(compare:)],
                         @"expected specific matcher strings");
}

- (void)testItShouldMatchReceivedMessagesForReceive {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields)];
    [subject raiseShields];
    STAssertTrue([matcher evaluate], @"expected positive match");
}

- (void)testItShouldNotMatchNonReceivedMessagesForReceive {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields)];
    [subject fighters];
    STAssertFalse([matcher evaluate], @"expected negative match");
}

- (void)testItShouldMatchReceivedMessagesForReceiveWithCount {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields) withCount:2];
    [subject raiseShields];
    [subject raiseShields];
    STAssertTrue([matcher evaluate], @"expected positive match");
}

- (void)testItShouldNotMatchNonReceivedMessagesForReceiveWithCount {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields) withCount:2];
    [subject fighters];
    STAssertFalse([matcher evaluate], @"expected negative match");
}

- (void)testItShouldMatchReceivedMessagesForReceiveWithCountAtLeast {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields) withCountAtLeast:2];
    [subject raiseShields];
    [subject raiseShields];
    [subject raiseShields];
    STAssertTrue([matcher evaluate], @"expected positive match");
}

- (void)testItShouldNotMatchNonReceivedMessagesForReceiveWithCountAtLeast {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(raiseShields) withCountAtLeast:2];
    [subject fighters];
    STAssertFalse([matcher evaluate], @"expected negative match");
}

- (void)testItShouldStubForReceiveAndReturn {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(crewComplement) andReturn:[KWValue valueWithUnsignedInt:42]];
    NSUInteger value = [subject crewComplement];
    STAssertTrue([matcher evaluate], @"expected positive match");
    STAssertTrue(value == 42u, @"expected stubbed value");
}

- (void)testItShouldStubForReceiveAndReturnWithCount {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(crewComplement) andReturn:[KWValue valueWithUnsignedInt:42] withCount:2];
    [subject crewComplement];
    NSUInteger value = [subject crewComplement];
    STAssertTrue([matcher evaluate], @"expected positive match");
    STAssertTrue(value == 42u, @"expected stubbed value");
}

- (void)testItShouldStubForReceiveAndReturnWithCountAtLeast {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(crewComplement) andReturn:[KWValue valueWithUnsignedInt:42] withCountAtLeast:2];
    [subject crewComplement];
    [subject crewComplement];
    NSUInteger value = [subject crewComplement];
    STAssertTrue([matcher evaluate], @"expected positive match");
    STAssertTrue(value == 42u, @"expected stubbed value");
}

- (void)testItShouldStubForReceiveAndReturnWithCountAtMost {
    id subject = [Cruiser cruiser];
    id matcher = [KWReceiveMatcher matcherWithSubject:subject];
    [matcher receive:@selector(crewComplement) andReturn:[KWValue valueWithUnsignedInt:42] withCountAtMost:2];
    [subject crewComplement];
    NSUInteger value = [subject crewComplement];
    STAssertTrue([matcher evaluate], @"expected positive match");
    STAssertTrue(value == 42u, @"expected stubbed value");
}

@end

#endif // #if KW_TESTS_ENABLED
Something went wrong with that request. Please try again.