Skip to content

Commit

Permalink
First cut at Bailador::Test, add some very basic tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Apr 7, 2012
1 parent 774bd83 commit 55fe612
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Bailador/Request.pm
Expand Up @@ -10,6 +10,10 @@ class Bailador::Request {
return %ret;
}

method new_for_request($meth, $path) {
self.new: env => { REQUEST_METHOD => $meth, REQUEST_URI => $path}
}

method port { $.env<SERVER_PORT> }
method request_uri { $.env<REQUEST_URI> }
method uri { self.request_uri }
Expand Down
30 changes: 30 additions & 0 deletions lib/Bailador/Test.pm
@@ -0,0 +1,30 @@
module Bailador::Test;

use Test;
use Bailador::App;

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;
}

sub route-doesnt-exist($meth, $path, $desc = '') is export {
my $req = Bailador::Request.new_for_request($meth, $path);
ok !Bailador::App.current.find_route($req), $desc;
}

sub response-status-is($meth, $path, $status, $desc) is export { ... }
sub response-status-isnt($meth, $path, $status, $desc) is export { ... }

sub response-content-is($meth, $path, $cont, $desc) is export { ... }
sub response-content-isnt($meth, $path, $cont, $desc) is export { ... }
sub response-content-is-deeply($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-headers-are-deeply($meth, $path, $cont, $desc) is export { ... }
sub response-headers-include($meth, $path, $cont, $desc) is export { ... }

sub bailador-response($meth, $path, *%opts) is export { ... }

sub read-logs is export { ... }
14 changes: 14 additions & 0 deletions t/01-route-existance.t
@@ -0,0 +1,14 @@
use Test;
use Bailador;
use Bailador::Test;

plan 4;

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

route-exists('GET', '/foo');
route-doesnt-exist('POST', '/foo');

route-exists('POST', '/bar');
route-doesnt-exist('GET', '/bar');

0 comments on commit 55fe612

Please sign in to comment.