Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Improved the naming convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hart committed Mar 9, 2012
1 parent c7c3e7b commit 177811f
Show file tree
Hide file tree
Showing 65 changed files with 697 additions and 691 deletions.
336 changes: 168 additions & 168 deletions Expecta.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions RDD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

### Asynchronous Tests

>`expect(x).isGoing.toEqual(y);` passes if x and y eventually become equivalent
>`expect(x).will.equaly);` passes if x and y eventually become equivalent
>
>`expect(x).isNotGoing.toEqual(y);` passes if x and y do not eventually become equivalent
>`expect(x).willNot.equaly);` passes if x and y do not eventually become equivalent
### BOOL

>`expect(x).toBeYes();` passes if x is a BOOL value of YES
>`expect(x).beYes();` passes if x is a BOOL value of YES
>
>`expect(x).toBeNo();` passes if x is a BOOL value of NO
>`expect(x).beNo();` passes if x is a BOOL value of NO
### Class

Expand All @@ -26,17 +26,17 @@
### Number

>`expect(x).toBeLessThan(y);` passes if x is less than y
>`expect(x).beLessThan(y);` passes if x is less than y
>
>`expect(x).toBeLessThanOrEqualTo(y);` passes if x is less than or equal to y
>`expect(x).beLessThanOrEqualTo(y);` passes if x is less than or equal to y
>
>`expect(x).toBeGreaterThan(y);` passes if x is greater than y
>`expect(x).beGreaterThan(y);` passes if x is greater than y
>
>`expect(x).toBeGreaterThanOrEqualTo(y);` passes if x is greater than or equal to y
>`expect(x).beGreaterThanOrEqualTo(y);` passes if x is greater than or equal to y
>
>`expect(x).toBeCloseTo(y, z);` passes if x is equal to y to a precision of z decimal places
>`expect(x).beCloseTo(y, z);` passes if x is equal to y to a precision of z decimal places
>
>`expect(x).toBeInTheRangeOf(y, z);` passes if x is in the range of [y, z]
>`expect(x).beInTheRangeOf(y, z);` passes if x is in the range of [y, z]
### Exceptions

Expand All @@ -50,7 +50,7 @@
### Collection

>`expect(x).toBeEmpty();` passes if x is empty
>`expect(x).beEmpty();` passes if x is empty
>
>`expect(x).toHaveCountOf(y);` passes if x contains y number of objects
>
Expand Down
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ vs.
**Expecta**
```objective-c
expect(@"foo").toEqual(@"foo");
expect(foo).Not.toEqual(1);
expect([bar isBar]).toEqual(YES);
expect(baz).toEqual(3.14159);
expect(@"foo").equal@"foo");
expect(foo).toNot.equal1);
expect([bar isBar]).equalYES);
expect(baz).equal3.14159);
```

## SETUP
Expand Down Expand Up @@ -56,73 +56,73 @@ Expecta is framework-agnostic. It works well with OCUnit (SenTestingKit) and OCU

## BUILT-IN MATCHERS

>`expect(x).toEqual(y);` compares objects or primitives x and y and passes if they are identical (==) or equivalent (isEqual:).
>`expect(x).equaly);` compares objects or primitives x and y and passes if they are identical (==) or equivalent (isEqual:).
>
>`expect(x).toBeIdenticalTo(y);` compares objects x and y and passes if they are identical and have the same memory address.
>`expect(x).beIdenticalTo(y);` compares objects x and y and passes if they are identical and have the same memory address.
>
>`expect(x).toBeNil();` passes if x is nil.
>`expect(x).beNil();` passes if x is nil.
>
>`expect(x).toBeTruthy();` passes if x evaluates to true (non-zero).
>`expect(x).beTruthy();` passes if x evaluates to true (non-zero).
>
>`expect(x).toBeFalsy();` passes if x evaluates to false (zero).
>`expect(x).beFalsy();` passes if x evaluates to false (zero).
>
>`expect(x).toContain(y);` passes if an instance of NSArray or NSString x contains y.
>`expect(x).contain(y);` passes if an instance of NSArray or NSString x contains y.
>
>`expect(x).toBeInstanceOf([Foo class]);` passes if x is an instance of a class Foo.
>`expect(x).beInstanceOf([Foo class]);` passes if x is an instance of a class Foo.
>
>`expect(x).toBeKindOf([Foo class]);` passes if x is an instance of a class Foo or if x is an instance of any class that inherits from the class Foo.
>`expect(x).beKindOf([Foo class]);` passes if x is an instance of a class Foo or if x is an instance of any class that inherits from the class Foo.
>
>`expect([Foo class]).toBeSubclassOf([Bar class]);` passes if the class Foo is a subclass of the class Bar or if it is identical to the class Bar. Use toBeKindOf() for class clusters.
>`expect([Foo class]).beSubclassOf([Bar class]);` passes if the class Foo is a subclass of the class Bar or if it is identical to the class Bar. Use beKindOf() for class clusters.
>
>`expect(x).toBeLessThan(y);`
>`expect(x).beLessThan(y);`
>
>`expect(x).toBeLessThanOrEqualTo(y);`
>`expect(x).beLessThanOrEqualTo(y);`
>
>`expect(x).toBeGreaterThan(y);`
>`expect(x).beGreaterThan(y);`
>
>`expect(x).toBeGreaterThanOrEqualTo(y);`
>`expect(x).beGreaterThanOrEqualTo(y);`
>
>`expect(x).toBeInTheRangeOf(y,z);`
>`expect(x).beInTheRangeOf(y,z);`
**More matchers are coming soon!**

## INVERTING MATCHERS

Every matcher's criteria can be inverted by prepending `.Not`: (It is with a capital `N` because `not` is a keyword in C++.)

>`expect(x).Not.toEqual(y);` compares objects or primitives x and y and passes if they are *not* equivalent.
>`expect(x).toNot.equaly);` compares objects or primitives x and y and passes if they are *not* equivalent.
## ASYNCHRONOUS TESTING

Every matcher can be made to perform asynchronous testing by prepending `.isGoing` or `.isNotGoing`:

>`expect(x).isGoing.toBeNil();` passes if x becomes nil before the timeout.
>`expect(x).will.beNil();` passes if x becomes nil before the timeout.
Default timeout is 1.0 second. This setting can be changed by calling `[Expecta setAsynchronousTestTimeout:x]`, where x is the desired timeout.

## WRITING NEW MATCHERS

Writing a new matcher is easy with special macros provided by Expecta. Take a look at how `.toBeKindOf()` matcher is defined:
Writing a new matcher is easy with special macros provided by Expecta. Take a look at how `.beKindOf()` matcher is defined:

`EXPMatchers+toBeKindOf.h`
`EXPMatchers+beKindOf.h`

```objective-c
#import "Expecta.h"

EXPMatcherInterface(toBeKindOf, (Class expected));
EXPMatcherInterface(beKindOf, (Class expected));
// 1st argument is the name of the matcher function
// 2nd argument is the list of arguments that may be passed in the function call.
// Multiple arguments are fine. (e.g. (int foo, float bar))

#define toBeAKindOf toBeKindOf
#define beAKindOf beKindOf
```
`EXPMatchers+toBeKindOf.m`
`EXPMatchers+beKindOf.m`
```objective-c
#import "EXPMatchers+toBeKindOf.h"
#import "EXPMatchers+beKindOf.h"
EXPMatcherImplementationBegin(toBeKindOf, (Class expected)) {
EXPMatcherImplementationBegin(beKindOf, (Class expected)) {
BOOL actualIsNil = (actual == nil);
BOOL expectedIsNil = (expected == nil);
Expand Down
7 changes: 4 additions & 3 deletions src/EXPExpect.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ typedef NSString *(^EXPStringBlock)();
@property(nonatomic) BOOL negative;
@property(nonatomic) BOOL asynchronous;

@property(nonatomic, readonly) EXPExpect *Not;
@property(nonatomic, readonly) EXPExpect *isGoing;
@property(nonatomic, readonly) EXPExpect *isNotGoing;
@property(nonatomic, readonly) EXPExpect *to;
@property(nonatomic, readonly) EXPExpect *toNot;
@property(nonatomic, readonly) EXPExpect *will;
@property(nonatomic, readonly) EXPExpect *willNot;

@property(nonatomic, copy) EXPBoolBlock prerequisiteBlock;
@property(nonatomic, copy) EXPBoolBlock matchBlock;
Expand Down
19 changes: 12 additions & 7 deletions src/EXPExpect.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ @implementation EXPExpect

@dynamic
actual,
Not,
isGoing,
isNotGoing;
to,
toNot,
will,
willNot;

@synthesize
actualBlock=_actualBlock,
Expand Down Expand Up @@ -54,18 +55,22 @@ - (void)dealloc {

#pragma mark -

- (EXPExpect *)Not {
- (EXPExpect *)to {
return self;
}

- (EXPExpect *)toNot {
self.negative = !self.negative;
return self;
}

- (EXPExpect *)isGoing {
- (EXPExpect *)will {
self.asynchronous = YES;
return self;
}

- (EXPExpect *)isNotGoing {
return self.isGoing.Not;
- (EXPExpect *)willNot {
return self.will.toNot;
}

#pragma mark -
Expand Down
3 changes: 3 additions & 0 deletions src/matchers/EXPMatchers+beFalsy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "Expecta.h"

EXPMatcherInterface(beFalsy, (void));
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeFalsy.h"
#import "EXPMatchers+beFalsy.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(toBeFalsy, (void)) {
EXPMatcherImplementationBegin(beFalsy, (void)) {
match(^BOOL{
if([actual isKindOfClass:[NSNumber class]]) {
return ![(NSNumber *)actual boolValue];
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/EXPMatchers+beGreaterThan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beGreaterThan, (id expected));
EXPMatcherInterface(beGreaterThan, (id expected));

#define beGreaterThan(expected) _beGreaterThan(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeGreaterThan.h"
#import "EXPMatchers+beGreaterThan.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(_toBeGreaterThan, (id expected)) {
EXPMatcherImplementationBegin(_beGreaterThan, (id expected)) {
match(^BOOL{
if ([actual respondsToSelector:@selector(compare:)]) {
return [actual compare:expected] == NSOrderedDescending;
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/EXPMatchers+beGreaterThanOrEqualTo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beGreaterThanOrEqualTo, (id expected));
EXPMatcherInterface(beGreaterThanOrEqualTo, (id expected));

#define beGreaterThanOrEqualTo(expected) _beGreaterThanOrEqualTo(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeGreaterThanOrEqualTo.h"
#import "EXPMatchers+beGreaterThanOrEqualTo.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(_toBeGreaterThanOrEqualTo, (id expected)) {
EXPMatcherImplementationBegin(_beGreaterThanOrEqualTo, (id expected)) {
match(^BOOL{
if ([actual respondsToSelector:@selector(compare:)]) {
return [actual compare:expected] != NSOrderedAscending;
Expand Down
3 changes: 3 additions & 0 deletions src/matchers/EXPMatchers+beIdenticalTo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "Expecta.h"

EXPMatcherInterface(beIdenticalTo, (void *expected));
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toEqual.h"
#import "EXPMatchers+equal.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(toBeIdenticalTo, (void *expected)) {
EXPMatcherImplementationBegin(beIdenticalTo, (void *expected)) {
match(^BOOL{
if(actual == expected) {
return YES;
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/EXPMatchers+beInTheRangeOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beInTheRangeOf, (id expectedLowerBound, id expectedUpperBound));
EXPMatcherInterface(beInTheRangeOf, (id expectedLowerBound, id expectedUpperBound));

#define beInTheRangeOf(expectedLowerBound, expectedUpperBound) _beInTheRangeOf(EXPObjectify((expectedLowerBound)), EXPObjectify((expectedUpperBound)))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeInTheRangeOf.h"
#import "EXPMatchers+beInTheRangeOf.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(_toBeInTheRangeOf, (id expectedLowerBound, id expectedUpperBound)) {
EXPMatcherImplementationBegin(_beInTheRangeOf, (id expectedLowerBound, id expectedUpperBound)) {
match(^BOOL{
if ([actual respondsToSelector:@selector(compare:)]) {
NSComparisonResult compareLowerBound = [expectedLowerBound compare: actual];
Expand Down
7 changes: 7 additions & 0 deletions src/matchers/EXPMatchers+beInstanceOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "Expecta.h"

EXPMatcherInterface(beInstanceOf, (Class expected));

#define beAnInstanceOf beInstanceOf
#define beMemberOf beInstanceOf
#define beAMemberOf beInstanceOf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "EXPMatchers+toBeInstanceOf.h"
#import "EXPMatchers+beInstanceOf.h"

EXPMatcherImplementationBegin(toBeInstanceOf, (Class expected)) {
EXPMatcherImplementationBegin(beInstanceOf, (Class expected)) {
BOOL actualIsNil = (actual == nil);
BOOL expectedIsNil = (expected == nil);

Expand Down
5 changes: 5 additions & 0 deletions src/matchers/EXPMatchers+beKindOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "Expecta.h"

EXPMatcherInterface(beKindOf, (Class expected));

#define beAKindOf beKindOf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "EXPMatchers+toBeKindOf.h"
#import "EXPMatchers+beKindOf.h"

EXPMatcherImplementationBegin(toBeKindOf, (Class expected)) {
EXPMatcherImplementationBegin(beKindOf, (Class expected)) {
BOOL actualIsNil = (actual == nil);
BOOL expectedIsNil = (expected == nil);

Expand Down
6 changes: 6 additions & 0 deletions src/matchers/EXPMatchers+beLessThan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beLessThan, (id expected));
EXPMatcherInterface(beLessThan, (id expected));

#define beLessThan(expected) _beLessThan(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeLessThan.h"
#import "EXPMatchers+beLessThan.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(_toBeLessThan, (id expected)) {
EXPMatcherImplementationBegin(_beLessThan, (id expected)) {
match(^BOOL{
if ([actual respondsToSelector:@selector(compare:)]) {
return [actual compare:expected] == NSOrderedAscending;
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/EXPMatchers+beLessThanOrEqualTo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "Expecta.h"

EXPMatcherInterface(_beLessThanOrEqualTo, (id expected));
EXPMatcherInterface(beLessThanOrEqualTo, (id expected));

#define beLessThanOrEqualTo(expected) _beLessThanOrEqualTo(EXPObjectify((expected)))
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "EXPMatchers+toBeLessThanOrEqualTo.h"
#import "EXPMatchers+beLessThanOrEqualTo.h"
#import "EXPMatcherHelpers.h"

EXPMatcherImplementationBegin(_toBeLessThanOrEqualTo, (id expected)) {
EXPMatcherImplementationBegin(_beLessThanOrEqualTo, (id expected)) {
match(^BOOL{
if ([actual respondsToSelector:@selector(compare:)]) {
return [actual compare:expected] != NSOrderedDescending;
Expand Down
5 changes: 5 additions & 0 deletions src/matchers/EXPMatchers+beNil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "Expecta.h"

EXPMatcherInterface(beNil, (void));

#define beNull beNil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "EXPMatchers+toBeNil.h"
#import "EXPMatchers+beNil.h"

EXPMatcherImplementationBegin(toBeNil, (void)) {
EXPMatcherImplementationBegin(beNil, (void)) {
match(^BOOL{
return actual == nil;
});
Expand Down
5 changes: 5 additions & 0 deletions src/matchers/EXPMatchers+beSubclassOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "Expecta.h"

EXPMatcherInterface(beSubclassOf, (Class expected));

#define beASubclassOf beSubclassOf
Loading

0 comments on commit 177811f

Please sign in to comment.