I'm having trouble getting Cedar matchers to accept object literals like @"strings"
or
[NSNumber numberWithInt:2]
. If I assign them to a variable then pass in the pointer it
works fine, but if I pass in a literal to the macro it fails while building with errors like
this:
Semantic Issue
error: no matching function for call to 'equal' [3]
For example, I've set up a blank Example project and added Cedar, then created a simple spec showing what seems to work and what doesn't:
#import <Cedar-iOS/SpecHelper.h>
using namespace Cedar::Matchers;
SPEC_BEGIN(ExampleSpec)
describe(@"Example", ^{
it(@"should compare scalars", ^{
expect(1+1).to(equal(2));
});
it(@"should compare objects", ^{
// Works fine
NSString* aString = @"something";
expect(aString).to(equal(aString));
// Works fine
NSString* bString = @"something";
expect(aString).to(equal(bString));
// Semantic Issue
// error: no matching function for call to 'equal' [3]
expect(aString).to(equal(@"something"));
// Semantic Issue
// error: no matching function for call to 'equal' [3]
NSNumber *two = [NSNumber numberWithInt:(1+1)];
expect([NSNumber numberWithInt:(1+1)]).to(equal([NSNumber numberWithInt:(2)]));
});
});
SPEC_END
I can run the iPhoneSpecs target in the Cedar project itself without an issue and it seems to pass in object literals to matcher macros just fine.
Here are the detailed instructions with how I set up the example project and where things seem to go wrong.
-
Create a new ARC iPhone project named Example with Xcode 4.2 including unit tests
-
Clone pivotal/cedar into a peer directory
$ git clone https://github.com/pivotal/cedar.git
-
Initialize the cedar submodules
$ cd cedar $ git submodule update --init Submodule 'Externals/OCMock' (git://github.com/pivotal/OCMock.git) registered for path 'Externals/OCMock' Submodule 'Spec/UIAutomation/jasmine-iphone' (git://github.com/pivotal/jasmine-iphone.git) registered for path 'Spec/UIAutomation/jasmine-iphone' Cloning into Externals/OCMock... remote: Counting objects: 674, done. remote: Compressing objects: 100% (161/161), done. remote: Total 674 (delta 456), reused 662 (delta 448) Receiving objects: 100% (674/674), 314.89 KiB | 429 KiB/s, done. Resolving deltas: 100% (456/456), done. Submodule path 'Externals/OCMock': checked out '0abfb4a37c09629cf435d372b64f98a740fd48ed' Cloning into Spec/UIAutomation/jasmine-iphone... remote: Counting objects: 15, done. remote: Compressing objects: 100% (11/11), done. remote: Total 15 (delta 4), reused 15 (delta 4) Receiving objects: 100% (15/15), done. Resolving deltas: 100% (4/4), done. Submodule path 'Spec/UIAutomation/jasmine-iphone': checked out '3cee16e01db1f667c11d9716f51b8e3e2fbabc75'
-
Build the Cedar-iOS framework
- Open Cedar.xcodeproj in Xcode
- Select the "Cedar-iOS > My Mac 64-bit" scheme
- Click Run and see "Build Succeeded"
-
Create a Cocoa Touch Application target for the tests
- Open the Example project
- Select the Example project in the project navigator
- Click Add Target from the bottom of the summary panel
- Choose iOS>Application>Empty Application
- Name it UISpecs
- Deselect use Core Data
- Select Use Automatic Reference Counting
- Deselect Include Unit Tests
- Click Finish
-
Add the Cedar-iOS Framework to the Example project
- In Finder, under ~/cedar/build/Debug-iphoneuniversal select Cedar-iOS.framework
- Drag that to the Frameworks group of the Example project in Xcode
- Select Copy items into destination group's folder (if needed)
- Add to targets UISpecs
- Click Finish, the result is that Cedar-iOS.framework is linked with the UISpecs target
- Add the -ObjC and -all_load Other Linker Flags to UISpecs
- Update main.m under UISpecs to run the CedarAppDelegate
- Build and Run UISpecs - at this point it opens the Simulator and runs fine (with no examples obviously)
- Copying and updating the cedar/Rakefile over to the Example project then running
rake uispecs
works fine too.
-
Write some examples
- Add a new blank ExampleSpec.mm to the UISpecs target
- Add some examples
-
Pointers inside the Cedar matcher macro calls work fine, literals and object instantiations don't. They give an error like:
Semantic Issue error: no matching function for call to 'equal' [3]