Permalink
Browse files

Refactor Bailador::Test a bit, implement response-content-is-deeply a…

…nd add a failing test for it
  • Loading branch information...
tadzik committed Apr 22, 2012
1 parent c2e59eb commit 479b56b22a59e0997f5e3826eba58bd1e21d2bc1
Showing with 20 additions and 10 deletions.
  1. +14 −9 lib/Bailador/Test.pm
  2. +6 −1 t/03-response-content.t
View
@@ -4,6 +4,11 @@ use Bailador::Request;
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 {
my $req = Bailador::Request.new_for_request($meth, $path);
ok Bailador::App.current.find_route($req), $desc;
@@ -15,30 +20,30 @@ sub route-doesnt-exist($meth, $path, $desc = '') is export {
}
sub response-status-is($meth, $path, $status, $desc = '') is export {
- my $req = Bailador::Request.new_for_request($meth, $path);
- my $resp = Bailador::dispatch_request($req);
+ my $resp = get-response($meth, $path);
is $resp.code, $status, $desc;
}
sub response-status-isnt($meth, $path, $status, $desc = '') is export {
- my $req = Bailador::Request.new_for_request($meth, $path);
- my $resp = Bailador::dispatch_request($req);
+ my $resp = get-response($meth, $path);
isnt $resp.code, $status, $desc;
}
sub response-content-is($meth, $path, $cont, $desc = '') is export {
- my $req = Bailador::Request.new_for_request($meth, $path);
- my $resp = Bailador::dispatch_request($req);
+ my $resp = get-response($meth, $path);
is ~$resp.content, $cont, $desc;
}
sub response-content-isnt($meth, $path, $cont, $desc = '') is export {
- my $req = Bailador::Request.new_for_request($meth, $path);
- my $resp = Bailador::dispatch_request($req);
+ my $resp = get-response($meth, $path);
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-unlike($meth, $path, $cont, $desc) is export { ... }
View
@@ -2,13 +2,18 @@ use Test;
use Bailador;
use Bailador::Test;
-plan 4;
+plan 5;
get '/foo' => sub { "foo" }
post '/bar' => sub { "bar" }
+get '/baz' => sub { { foo => "bar", baz => 5 } }
+
response-content-is 'GET', '/foo', "foo";
response-content-isnt 'GET', '/bar', "bar";
response-content-is 'POST', '/bar', "bar";
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.