Permalink
Browse files

Merged #12, #14 and #15. Updated README. Added `notTo`.

  • Loading branch information...
1 parent 3206188 commit b4527c43cb4b5c458d111c4314d401919fcf6078 @petejkim petejkim committed Mar 27, 2012
Showing with 66 additions and 48 deletions.
  1. +2 −2 Expecta.podspec
  2. +2 −0 Expecta.xcodeproj/project.pbxproj
  3. +1 −1 LICENSE
  4. +0 −6 RDD.md
  5. +35 −29 README.md
  6. +1 −0 src/EXPExpect.h
  7. +15 −10 src/EXPExpect.m
  8. +1 −0 src/ExpectaSupport.m
  9. +9 −0 test/ExpectationTest.m
View
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = 'Expecta'
- s.version = '0.1.3'
+ s.version = '0.2.0'
s.license = 'MIT'
s.summary = 'A matcher framework for Objective-C & Cocoa'
s.homepage = 'http://github.com/petejkim/expecta'
s.author = { 'Peter Jihoon Kim' => 'raingrove@gmail.com' }
- s.source = { :git => 'http://github.com/petejkim/expecta.git', :tag => 'v0.1.3' }
+ s.source = { :git => 'http://github.com/petejkim/expecta.git', :tag => 'v0.2.0' }
s.description = %{
Expecta is a matcher framework for Objective-C and Cocoa. The main
@@ -230,6 +230,7 @@
E942971113B45ADD0038708B /* EXPMatchers+beIdenticalToTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EXPMatchers+beIdenticalToTest.m"; sourceTree = "<group>"; };
E942971413B45C8D0038708B /* EXPMatchers+beIdenticalTo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "EXPMatchers+beIdenticalTo.h"; sourceTree = "<group>"; };
E942971513B45C8E0038708B /* EXPMatchers+beIdenticalTo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EXPMatchers+beIdenticalTo.m"; sourceTree = "<group>"; };
+ E95368421521B5FC00AA3B81 /* Expecta.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Expecta.podspec; sourceTree = "<group>"; };
E9685DBB13B5E39300ADF2D7 /* ExpectaSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExpectaSupport.h; sourceTree = "<group>"; };
E9685DBE13B5E5DA00ADF2D7 /* ExpectaSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExpectaSupport.m; sourceTree = "<group>"; };
E969C52213B5FD02006BB8B1 /* EXPFailTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EXPFailTest.m; sourceTree = "<group>"; };
@@ -331,6 +332,7 @@
E9ACDF0113B2DD520010F4D7 = {
isa = PBXGroup;
children = (
+ E95368421521B5FC00AA3B81 /* Expecta.podspec */,
E9ACDF9413B2DEF30010F4D7 /* LICENSE */,
E9ACDF9513B2DEF30010F4D7 /* README.md */,
E9A6BAAE13B7183100950250 /* RDD.md */,
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011-2012 Peter Jihoon Kim
+Copyright (c) 2011-2012 Peter Jihoon Kim and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -2,12 +2,6 @@
## To Be Implemented
-### Asynchronous Tests
-
->`expect(x).will.equaly);` passes if x and y eventually become equivalent
->
->`expect(x).willNot.equaly);` passes if x and y do not eventually become equivalent
-
### BOOL
>`expect(x).beYes();` passes if x is a BOOL value of YES
View
@@ -1,10 +1,14 @@
-# Expecta
+# Expecta 0.2.0
A Matcher Framework for Objective-C/Cocoa
+## NOTICE
+
+Expecta 0.2.x has a new syntax that is slightly different from Expecta 0.1.x. For example `expect(x).toEqual(y)` should now be written as `expect(x).to.equal(y)`.
+
## INTRODUCTION
-The main advantage of using Expecta over other matcher frameworks is that you do not have to specify the data types. Also, the syntax of Expecta matchers is much more readable and does not suffer from parenthesitis. If you have used [Jasmine](http://pivotal.github.com/jasmine/) before, you will feel right at home!
+The main advantage of using Expecta over other matcher frameworks is that you do not have to specify the data types. Also, the syntax of Expecta matchers is much more readable and does not suffer from parenthesitis.
**OCHamcrest**
@@ -20,8 +24,8 @@ vs.
**Expecta**
```objective-c
-expect(@"foo").equal(@"foo");
-expect(foo).toNot.equal(1);
+expect(@"foo").to.equal(@"foo"); // `to` is a syntatic sugar and can be safely omitted.
+expect(foo).notTo.equal(1);
expect([bar isBar]).to.equal(YES);
expect(baz).to.equal(3.14159);
```
@@ -31,16 +35,16 @@ expect(baz).to.equal(3.14159);
Use [CocoaPods](https://github.com/CocoaPods/CocoaPods)
```ruby
-dependency 'Expecta', '~> 0.1.3'
-# dependency 'Specta', '~> 0.1.3' # specta bdd framework
+dependency 'Expecta', '~> 0.2.0'
+# dependency 'Specta', '~> 0.2.0' # specta bdd framework
```
or
1. Clone from Github.
2. Run `rake` in project root to build.
3. Copy and add all header files in `products` folder to the Spec/Test target in your Xcode project.
-4. For **OS X projects**, copy and add `libExpecta-macosx.a` in `products` folder to the Spec/Test target in your Xcode project.
+4. For **OS X projects**, copy and add `libExpecta-macosx.a` in `products` folder to the Spec/Test target in your Xcode project.
For **iOS projects**, copy and add `libExpecta-ios-universal.a` in `products` folder to the Spec/Test target in your Xcode project.
5. Add `-ObjC` to the "Other Linker Flags" build setting for the Spec/Test target in your Xcode project.
6. Add the following to your test code.
@@ -56,43 +60,43 @@ Expecta is framework-agnostic. It works well with OCUnit (SenTestingKit) and OCU
## BUILT-IN MATCHERS
->`expect(x).equal(y);` compares objects or primitives x and y and passes if they are identical (==) or equivalent (isEqual:).
+>`expect(x).to.equal(y);` compares objects or primitives x and y and passes if they are identical (==) or equivalent (isEqual:).
>
->`expect(x).beIdenticalTo(y);` compares objects x and y and passes if they are identical and have the same memory address.
+>`expect(x).to.beIdenticalTo(y);` compares objects x and y and passes if they are identical and have the same memory address.
>
->`expect(x).beNil();` passes if x is nil.
+>`expect(x).to.beNil();` passes if x is nil.
>
->`expect(x).beTruthy();` passes if x evaluates to true (non-zero).
+>`expect(x).to.beTruthy();` passes if x evaluates to true (non-zero).
>
->`expect(x).beFalsy();` passes if x evaluates to false (zero).
+>`expect(x).to.beFalsy();` passes if x evaluates to false (zero).
>
->`expect(x).contain(y);` passes if an instance of NSArray or NSString x contains y.
+>`expect(x).to.contain(y);` passes if an instance of NSArray or NSString x contains y.
>
->`expect(x).beInstanceOf([Foo class]);` passes if x is an instance of a class Foo.
+>`expect(x).to.beInstanceOf([Foo class]);` passes if x is an instance of a 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(x).to.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]).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([Foo class]).to.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).beLessThan(y);`
+>`expect(x).to.beLessThan(y);`
>
->`expect(x).beLessThanOrEqualTo(y);`
+>`expect(x).to.beLessThanOrEqualTo(y);`
>
->`expect(x).beGreaterThan(y);`
+>`expect(x).to.beGreaterThan(y);`
>
->`expect(x).beGreaterThanOrEqualTo(y);`
+>`expect(x).to.beGreaterThanOrEqualTo(y);`
>
->`expect(x).beInTheRangeOf(y,z);`
+>`expect(x).to.beInTheRangeOf(y,z);`
>
->`expect(x).beCloseTo(y);`
+>`expect(x).to.beCloseTo(y);`
**More matchers are coming soon!**
## INVERTING MATCHERS
-Every matcher's criteria can be inverted by prepending `.toNot`:
+Every matcher's criteria can be inverted by prepending `.notTo` or `.toNot`:
->`expect(x).toNot.equal(y);` compares objects or primitives x and y and passes if they are *not* equivalent.
+>`expect(x).notTo.equal(y);` compares objects or primitives x and y and passes if they are *not* equivalent.
## ASYNCHRONOUS TESTING
@@ -211,12 +215,14 @@ You can find the public Tracker project [here](https://www.pivotaltracker.com/pr
### CONTRIBUTORS
-* [kseebaldt](https://github.com/kseebaldt)
-* [akitchen](https://github.com/akitchen)
-* [joncooper](https://github.com/joncooper)
-* [twobitlabs](https://github.com/twobitlabs)
+* [Kurtis Seebaldt](https://github.com/kseebaldt)
+* [Andrew Kitchen](https://github.com/akitchen)
+* [Jon Cooper](https://github.com/joncooper)
+* [Two Bit Labs](https://github.com/twobitlabs)
+* [David Hart](https://github.com/TrahDivad)
+* [Luke Redpath](https://github.com/lukeredpath)
## LICENSE
-Copyright (c) 2011-2012 Peter Jihoon Kim. This software is licensed under the [MIT License](http://github.com/petejkim/expecta/raw/master/LICENSE).
+Copyright (c) 2011-2012 Peter Jihoon Kim and contributors. This software is licensed under the [MIT License](http://github.com/petejkim/expecta/raw/master/LICENSE).
View
@@ -21,6 +21,7 @@
@property(nonatomic, readonly) EXPExpect *to;
@property(nonatomic, readonly) EXPExpect *toNot;
+@property(nonatomic, readonly) EXPExpect *notTo;
@property(nonatomic, readonly) EXPExpect *will;
@property(nonatomic, readonly) EXPExpect *willNot;
View
@@ -11,6 +11,7 @@ @implementation EXPExpect
actual,
to,
toNot,
+ notTo,
will,
willNot;
@@ -20,7 +21,7 @@ @implementation EXPExpect
negative=_negative,
asynchronous=_asynchronous,
lineNumber=_lineNumber,
-fileName=_fileName;
+ fileName=_fileName;
- (id)initWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName {
self = [super init];
@@ -50,6 +51,10 @@ - (EXPExpect *)toNot {
return self;
}
+- (EXPExpect *)notTo {
+ return [self toNot];
+}
+
- (EXPExpect *)will {
self.asynchronous = YES;
return self;
@@ -78,13 +83,13 @@ - (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual {
if([*actual isKindOfClass:[EXPUnsupportedObject class]]) {
EXPFail(self.testCase, self.lineNumber, self.fileName,
[NSString stringWithFormat:@"expecting a %@ is not supported", ((EXPUnsupportedObject *)*actual).type]);
- } else {
- BOOL failed;
- if([matcher respondsToSelector:@selector(meetsPrerequesiteFor:)] &&
+ } else {
+ BOOL failed = NO;
+ if([matcher respondsToSelector:@selector(meetsPrerequesiteFor:)] &&
![matcher meetsPrerequesiteFor:*actual]) {
failed = YES;
} else {
- BOOL matchResult;
+ BOOL matchResult = NO;
if(self.asynchronous) {
NSTimeInterval timeOut = [Expecta asynchronousTestTimeout];
NSDate *expiryDate = [NSDate dateWithTimeIntervalSinceNow:timeOut];
@@ -103,11 +108,11 @@ - (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual {
failed = self.negative ? matchResult : !matchResult;
}
if(failed) {
- NSString *message;
-
+ NSString *message = nil;
+
if(self.negative) {
if ([matcher respondsToSelector:@selector(failureMessageForNotTo:)]) {
- message = [matcher failureMessageForNotTo:*actual];
+ message = [matcher failureMessageForNotTo:*actual];
}
} else {
if ([matcher respondsToSelector:@selector(failureMessageForTo:)]) {
@@ -117,7 +122,7 @@ - (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual {
if (message == nil) {
message = @"Match Failed.";
}
-
+
EXPFail(self.testCase, self.lineNumber, self.fileName, message);
}
}
@@ -178,7 +183,7 @@ - (NSString *)failureMessageForNotTo:(id)actual
- (void (^)(void))dispatch
{
__block id blockExpectation = _expectation;
-
+
return [^{
[blockExpectation applyMatcher:self];
} copy];
@@ -96,6 +96,7 @@ id _EXPObjectify(char *type, ...) {
}
void EXPFail(id testCase, int lineNumber, char *fileName, NSString *message) {
+ NSLog(@"%s:%d %@", fileName, lineNumber, message);
NSString *reason = [NSString stringWithFormat:@"%s:%d %@", fileName, lineNumber, message];
NSException *exception = [NSException exceptionWithName:@"Expecta Error" reason:reason userInfo:nil];
@@ -17,6 +17,15 @@ - (void)test_expect {
assertEquals(x.testCase, self);
}
+- (void)test_expect_NotTo {
+ x = expect(@"foo");
+ assertFalse(x.negative);
+ x = expect(@"foo").notTo;
+ assertTrue(x.negative);
+ x = expect(@"foo").toNot;
+ assertTrue(x.negative);
+}
+
- (void)test_expect_nil {
assertNil(expect(nil).actual);
}

0 comments on commit b4527c4

Please sign in to comment.