ciscoheat / buddy

Your friendly BDD testing library for Haxe!
MIT License
96 stars 24 forks source link

Feature Request: Allow `err(e:Dynamic)` as a second parameter to an `it` function. #21

Closed brendanjerwin closed 10 years ago

brendanjerwin commented 10 years ago

It'd be nice to be able to wire it right up as an error handler on promises and callbacks.

Then the test would fail with a nice error message when the error callback is called.

Something like this:

            it("should make a GET request with promise", function(done, err) {
                var p = c.getJson("/hello_world");
                p.then(function(r) {
                    r.statusCode.should.be(200);
                    r.data.title.should.be('Hello World');
                    done();
                });
                p.catchError(err);  // <-- This would fail the test with a message as passed to err()
            });
ciscoheat commented 10 years ago

Looks like a nice feature, but to make it simple to use the err function type must match what is passed to the promise library, in this case to the catchError method. Is it possible to guarantee this? Otherwise you need to partially apply the err function, which could be as complicated as failing the test manually. What do you think?

In any case, there needs to be a way to fail a test properly. That'll be a next version feature. :)

brendanjerwin commented 10 years ago

I'm looking at promhx, which takes a Dynamic, so it seems simple to me. :)

ciscoheat commented 10 years ago

Sure, but I'd like a bit more generically applicable features.

ciscoheat commented 10 years ago

@brendanjerwin Good news! This is now implemented (0.13.0), but it will use a method called fail on the BuddySuite, so it can be used even if the function(done) isn't specified.

Check out https://github.com/ciscoheat/buddy#failing-tests for some documentation. Thanks for another useful request!

brendanjerwin commented 10 years ago

Awesome! Yeah, now that I see it, putting the method on BuddySuite seems obvious. :)