Skip to content

Instantly share code, notes, and snippets.

@cstar
Created May 13, 2011 12:33
Show Gist options
  • Save cstar/970445 to your computer and use it in GitHub Desktop.
Save cstar/970445 to your computer and use it in GitHub Desktop.
Fake your webmachine requests for unit testing.
make_wrq(Method, RawPath, Headers) ->
{ok, Dispatch} = file:consult(filename:join(
[filename:dirname(code:which(?MODULE)),
"..", "priv", "dispatch.conf"])),
R0 = wrq:create(Method, {1,1}, RawPath, mochiweb_headers:from_list(Headers)),
R1 = wrq:set_peer("127.0.0.1", R0),
{_, _, HostTokens, Port, PathTokens, Bindings, AppRoot, StringPath} =
webmachine_dispatcher:dispatch("127.0.0.1", RawPath, Dispatch),
wrq:load_dispatch_data(Bindings,
HostTokens,
Port,
PathTokens,
AppRoot,
StringPath,
R1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment