librelist archives

« back to archive

Near-English test expectations with Flask-Should-DSL

Near-English test expectations with Flask-Should-DSL

From:
Graeme Coupar
Date:
2012-09-22 @ 15:38
Hi all, 

I'm just posting to let you know about a new flask extension that I've 
been working on recently, Flask-Should-DSL.  It provides some matchers for
the should-dsl python package, to allow test expectations to be written in
something close to English (similar to the RSpec-Expectations library for 
Ruby).

For example, you can now write a test like:

    response = app.get('/json')
    response |should| be_200
    response |should| have_json({'a': 'b'})

Where previously you might have written:

    response = app.get('/json')
    self.assert200(response)
    self.assertEqual({'a': 'b'}, response.json)

There are also other matchers to check the status code of the response, to
check if the response is a redirect elsewhere, and to check the headers of
the response.

The extension can be used in combination with Flask-Testing or just on 
it's own, and more information can be found at 
http://obmarg.github.com/flask-should-dsl

Any feedback (or pull requests) would be more than welcome.

Thanks
Graeme