Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added more explicit information about using Cedar matchers to the

README; incorporated feature to select spec classes to run using an
environment variable (from Jonah@carbonfive); (nb) for consistency with
the ability to limit spec classes the runAllSpecs() method is now
deprecated in favor of runSpecs().
  • Loading branch information...
commit feebfc80df32095a697bb9afcc4c4ee6df28f8a4 2 parents d7b62c4 + 8015bea
Adam Milligan authored
View
32 README.markdown
@@ -29,7 +29,7 @@ BDD-style testing using Objective-C
#import <Cedar/Cedar.h>
int main (int argc, const char *argv[]) {
- return runAllSpecs();
+ return runSpecs();
}
* Write your specs. Cedar provides the SpecHelper.h file with some minimal
@@ -134,23 +134,21 @@ Here is a list of built-in matchers you can use:
expect(...).to(contain(@"something"));
expect(...).to(be_empty());
+These matchers use C++ templates for type deduction. You'll need to do two things to use them:
+
+* Change the file extension for each of your spec files from .m to .mm (this will tell the
+compiler that the file contains C++ code).
+
+* Add the following line to the top of your spec files, after the file includes:
+
+ using namespace Cedar::Matchers;
+
It's also theoretically very easy to add your own matchers without modifying the
-Cedar library (more on this later). To start using these matchers in your spec
-file place `using namespace Cedar::Matchers;` before SPEC_BEGIN declaration
-and change that spec file's extension from .m to .mm.
-
-This matcher library is new, and not hardly battle-hardened. It also breaks Apple's GCC compiler,
-and versions 2.0 and older of the LLVM compiler (this translates to any compiler shipped with a
-version of Xcode before 4.1). Fortunately, LLVM 2.1 fixes the issues. If you'd prefer a more
-stable matcher library, you can still easily use [OCHamcrest](http://code.google.com/p/hamcrest/).
-Build and link the Hamcrest framework by following their instructions, and add the following at
-the top of your spec files:
-
- #define HC_SHORTHAND
- #import <OCHamcrest/OCHamcrest.h>
-
-Pivotal also has a fork of a [GitHub import of the OCHamcrest codebase](http://github.com/pivotal/OCHamcrest).
-This fork contains our iPhone-specific static framework target.
+Cedar library (more on this later).
+
+These matchers will break Apple's GCC compiler, and versions 2.0 and older of the LLVM compiler
+(this translates to any compiler shipped with a version of Xcode before 4.1). Fortunately,
+LLVM 2.1 fixes the issues.
Note: If you decide to use another matcher library that uses `expect(...)` to
build its expectations (e.g. [Expecta](http://github.com/petejkim/expecta)) you
View
28 Source/CDRFunctions.m
@@ -5,6 +5,7 @@
#import "CDRExampleReporter.h"
#import "CDRDefaultReporter.h"
#import "SpecHelper.h"
+#import "CDRFunctions.h"
BOOL CDRClassIsOfType(Class class, const char * const className) {
if (strcmp(className, class_getName(class))) {
@@ -82,9 +83,26 @@ Class CDRReporterClassFromEnv(const char *defaultReporterClassName) {
return reporterClass;
}
-int runSpecsWithCustomExampleReporter(NSArray *specClasses, id<CDRExampleReporter> reporter) {
+NSArray *CDRSpecClassesToRun() {
+ char *envSpecClassNames = getenv("CEDAR_SPEC_CLASSES");
+ if (envSpecClassNames) {
+ NSArray *specClassNames = [[NSString stringWithCString:envSpecClassNames encoding:NSUTF8StringEncoding] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+ NSMutableArray *specClassesToRun = [NSMutableArray arrayWithCapacity:[specClassNames count]];
+ for (NSString *className in specClassNames) {
+ Class specClass = NSClassFromString(className);
+ if (specClass) {
+ [specClassesToRun addObject:specClass];
+ }
+ }
+ return [[specClassesToRun copy] autorelease];
+ }
+ return nil;
+}
+
+int runSpecsWithCustomExampleReporter(id<CDRExampleReporter> reporter) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSArray *specClasses = CDRSpecClassesToRun();
if (!specClasses) {
specClasses = CDRSelectClasses(^(Class class) { return CDRClassIsOfType(class, "CDRSpec"); });
}
@@ -108,7 +126,7 @@ int runSpecsWithCustomExampleReporter(NSArray *specClasses, id<CDRExampleReporte
return result;
}
-int runAllSpecs() {
+int runSpecs() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Class reporterClass = CDRReporterClassFromEnv("CDRDefaultReporter");
@@ -117,8 +135,12 @@ int runAllSpecs() {
}
id<CDRExampleReporter> reporter = [[[reporterClass alloc] init] autorelease];
- int result = runSpecsWithCustomExampleReporter(NULL, reporter);
+ int result = runSpecsWithCustomExampleReporter(reporter);
[pool drain];
return result;
}
+
+int runAllSpecs() {
+ return runSpecs();
+}
View
2  Source/CDROTestRunner.m
@@ -16,7 +16,7 @@ void runTests(id self, SEL _cmd, id ignored) {
}
id<CDRExampleReporter> reporter = [[[reporterClass alloc] init] autorelease];
- int result = runSpecsWithCustomExampleReporter(NULL, reporter);
+ int result = runSpecsWithCustomExampleReporter(reporter);
// otest always returns 0 as its exit code even if any test fails;
// we need to forcibly exit with correct exit code to make CI happy.
View
7 Source/Headers/CDRFunctions.h
@@ -4,6 +4,7 @@
Class CDRReporterClassFromEnv(const char *defaultReporterClassName);
-int runAllSpecs();
-int runAllSpecsWithCustomExampleReporter(id<CDRExampleReporter> runner);
-int runSpecsWithCustomExampleReporter(NSArray *specClasses, id<CDRExampleReporter> runner);
+int runSpecs();
+int runAllSpecs() __attribute__((deprecated));
+int runSpecsWithCustomExampleReporter(id<CDRExampleReporter> runner);
+NSArray *specClassesToRun();
View
2  Source/iPhone/CDRExampleReporterViewController.m
@@ -26,7 +26,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
- (void)startSpecs {
- runSpecsWithCustomExampleReporter(NULL, self);
+ runSpecsWithCustomExampleReporter(self);
}
- (void)pushRootSpecStatusController:(NSArray *)groups {
View
2  Source/iPhone/CedarApplicationDelegate.m
@@ -13,7 +13,7 @@ void runSpecsWithinUIApplication() {
exitStatus = -999;
} else {
id<CDRExampleReporter> reporter = [[[reporterClass alloc] init] autorelease];
- exitStatus = runSpecsWithCustomExampleReporter(NULL, reporter);
+ exitStatus = runSpecsWithCustomExampleReporter(reporter);
}
UIApplication *application = [UIApplication sharedApplication];
View
2  Spec/Focused/main.m
@@ -9,7 +9,7 @@
BOOL wereExpectedCallsMade(NSArray *actuallyCalled, NSArray *expectedCalls);
int main (int argc, const char *argv[]) {
- int result = runAllSpecs();
+ int result = runSpecs();
BOOL expectedCallsMade =
wereExpectedCallsMade(calledInFocusedSpec__, expectedCallsInFocusedSpec__) &&
View
2  Spec/main.m
@@ -1,5 +1,5 @@
#import <Cedar/Cedar.h>
int main (int argc, const char *argv[]) {
- return runAllSpecs();
+ return runSpecs();
}

0 comments on commit feebfc8

Please sign in to comment.
Something went wrong with that request. Please try again.