specta / expecta

A Matcher Framework for Objective-C/Cocoa
MIT License
1.59k stars 158 forks source link

Custom matcher for promises #181

Open sbycrosz opened 8 years ago

sbycrosz commented 8 years ago

Context: I'm testing a Promise created using PromiseKit

What I have now:

promise.then(^(id result){
                            expect(result).to.equal(expected);
                        }).catch(^(NSError *error){ 
                            failure(error);
                        }).finally(^(){
                            done();
                        });

which the lazy old me use as a macro

#define AssertPromise(promise, expected) promise.then(^(id result){ expect(result).to.equal(expected);}).catch(^(NSError *error){ failure(error);}).finally(^(){done();});

What I wanted (similar library in JS: https://github.com/domenic/chai-as-promised/):

expect(promise).to.be.resolvedAs(expected)

Currently I am stuck on implementing the match method of EXPMatcher since it expects a boolean, but then we need to wait until the promise get resolved.

Would this kind of api be possible? Any kind of direction would be nice :)

Cheers,