[99s-extend] populating #http_req for unit testing

Eduardo Gurgel edgurgel at gmail.com
Sat Apr 13 13:12:39 CEST 2013


On Thu, Apr 11, 2013 at 8:37 PM, Brown, Kevin <Kevin.Brown at turner.com>wrote:

>
> Cowfolk,
>
> I am doing something like this to create an #http_req suitable for unit
> testing my resource callbacks:
>


I use the library meck(https://github.com/eproxus/meck) to test stuff doing
something like this:

some_test() ->
  meck:expect(cowboy_req, binding, 2, {<<"app_key">>, req} )
  ?assertEqual({ok, req, empty},
                 websocket_handler:websocket_init(transport, req, opts)),
  ?assert(meck:validate(cowboy_req)).

I use simple atoms as input and mock the cowboy_req functions to return
atoms that would represent the correct or the wrong answer.

The real implementation or how cowboy represent stuff is not important
here, just the output pattern like {Binding, Req}.

That's it

-- 

Eduardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ninenines.eu/archives/extend/attachments/20130413/f1b70800/attachment.html>


More information about the Extend mailing list