Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranguard committed Jan 16, 2014
1 parent 86e4940 commit 73ab00d
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions t/plack/mcless.t
@@ -1,35 +1,63 @@
use strict;

use Plack::App::File;
use Plack::Middleware::MCLess;

use Test::More;
use Plack::Test;
use Plack::Builder;
use HTTP::Request::Common;

use Data::Dumper;
my $app = builder {

enable "Plack::Middleware::MCLess",
root => "t/plack/css",
files => ['t/plack/css/style.less'];

return sub {
my $env = shift;
[ 200,
[ 'Content-type', 'text/plain' ],
[ map { $_ . $/ } @{ $env->{'psgix.assets_less'} } ]
];
}
};

my $app = Plack::App::File->new(root => "t/plack/css");
$app = Plack::Middleware::MCLess->wrap($app, root => "t/plack/css");

my $assets;
my $total = 1;

test_psgi $app, sub {
my $cb = shift;

my $res = $cb->(GET "/foo.less");
is $res->code, 200;
is $res->content_type, 'text/css';
like $res->content, qr/color: #4D926F;/i, "Content match for foo.less";
{
my $res = $cb->( GET 'http://localhost/' );
is( $res->code, 200 );
$assets = [ split( $/, $res->content ) ];
is @$assets, $total, "Number of assets matches";
}

{
like( $assets->[0], qr/\.css$/, '.css file extension' );
my $res = $cb->( GET 'http://localhost' . $assets->[0] );
is $res->code, 200;
is $res->content_type, 'text/css';
is $res->content, "#header{color:#4d926f}h2{color:#4d926f}", "Content matches";
}

# Something that uses includes
$res = $cb->(GET "/style.less");
is $res->code, 200;
is $res->content_type, 'text/css';
like $res->content, qr/\scolor: #4D926F;/i;

$res = $cb->(GET "/missing.less");
is $res->code, 404, '404 for a missing less file';
};

eval {
builder {

$res = $cb->(GET "/broken.less");
is $res->code, 500, '500 for a broken less file';
enable "Plack::Middleware::MCLess",
root => "t/plack/css",
files => ['t/plack/css/broken.less'];

};
};
my $error = $@;
ok $error =~ /ParseError/, 'Error ok';

done_testing;

0 comments on commit 73ab00d

Please sign in to comment.