From 479b56b22a59e0997f5e3826eba58bd1e21d2bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20So=C5=9Bnierz?= Date: Sun, 22 Apr 2012 10:51:27 +0200 Subject: [PATCH] Refactor Bailador::Test a bit, implement response-content-is-deeply and add a failing test for it --- lib/Bailador/Test.pm | 23 ++++++++++++++--------- t/03-response-content.t | 7 ++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Bailador/Test.pm b/lib/Bailador/Test.pm index 9e4a42e..23a1763 100644 --- a/lib/Bailador/Test.pm +++ b/lib/Bailador/Test.pm @@ -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 { ... } diff --git a/t/03-response-content.t b/t/03-response-content.t index 71f9dd5..5d36da8 100644 --- a/t/03-response-content.t +++ b/t/03-response-content.t @@ -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 };