Skip to content

Commit

Permalink
Refactor Bailador::Test a bit, implement response-content-is-deeply a…
Browse files Browse the repository at this point in the history
…nd add a failing test for it
  • Loading branch information
Tadeusz Sośnierz committed Apr 22, 2012
1 parent c2e59eb commit 479b56b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 14 additions & 9 deletions lib/Bailador/Test.pm
Expand Up @@ -4,6 +4,11 @@ use Bailador::Request;


module Bailador::Test; module Bailador::Test;


sub get-response($meth, $path) {
my $req = Bailador::Request.new_for_request($meth, $path);
Bailador::dispatch_request($req);
}

sub route-exists($meth, $path, $desc = '') is export { sub route-exists($meth, $path, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path); my $req = Bailador::Request.new_for_request($meth, $path);
ok Bailador::App.current.find_route($req), $desc; ok Bailador::App.current.find_route($req), $desc;
Expand All @@ -15,30 +20,30 @@ sub route-doesnt-exist($meth, $path, $desc = '') is export {
} }


sub response-status-is($meth, $path, $status, $desc = '') is export { sub response-status-is($meth, $path, $status, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path); my $resp = get-response($meth, $path);
my $resp = Bailador::dispatch_request($req);
is $resp.code, $status, $desc; is $resp.code, $status, $desc;
} }


sub response-status-isnt($meth, $path, $status, $desc = '') is export { sub response-status-isnt($meth, $path, $status, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path); my $resp = get-response($meth, $path);
my $resp = Bailador::dispatch_request($req);
isnt $resp.code, $status, $desc; isnt $resp.code, $status, $desc;
} }


sub response-content-is($meth, $path, $cont, $desc = '') is export { sub response-content-is($meth, $path, $cont, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path); my $resp = get-response($meth, $path);
my $resp = Bailador::dispatch_request($req);
is ~$resp.content, $cont, $desc; is ~$resp.content, $cont, $desc;
} }


sub response-content-isnt($meth, $path, $cont, $desc = '') is export { sub response-content-isnt($meth, $path, $cont, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path); my $resp = get-response($meth, $path);
my $resp = Bailador::dispatch_request($req);
isnt ~$resp.content, $cont, $desc; isnt ~$resp.content, $cont, $desc;
} }


sub response-content-is-deeply($meth, $path, $cont, $desc) is export { ... } sub response-content-is-deeply($meth, $path, $y, $desc = '') is export {
my $resp = get-response($meth, $path);
is_deeply ~$resp.content, $y, $desc;
}

sub response-content-like($meth, $path, $cont, $desc) is export { ... } sub response-content-like($meth, $path, $cont, $desc) is export { ... }
sub response-content-unlike($meth, $path, $cont, $desc) is export { ... } sub response-content-unlike($meth, $path, $cont, $desc) is export { ... }


Expand Down
7 changes: 6 additions & 1 deletion t/03-response-content.t
Expand Up @@ -2,13 +2,18 @@ use Test;
use Bailador; use Bailador;
use Bailador::Test; use Bailador::Test;


plan 4; plan 5;


get '/foo' => sub { "foo" } get '/foo' => sub { "foo" }
post '/bar' => sub { "bar" } post '/bar' => sub { "bar" }


get '/baz' => sub { { foo => "bar", baz => 5 } }

response-content-is 'GET', '/foo', "foo"; response-content-is 'GET', '/foo', "foo";
response-content-isnt 'GET', '/bar', "bar"; response-content-isnt 'GET', '/bar', "bar";


response-content-is 'POST', '/bar', "bar"; response-content-is 'POST', '/bar', "bar";
response-content-isnt 'POST', '/foo', "foo"; response-content-isnt 'POST', '/foo', "foo";

todo 'returning complex structs NYI';
response-content-is-deeply 'GET', '/baz', { foo => "bar", baz => 5 };

0 comments on commit 479b56b

Please sign in to comment.