Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Created September 3, 2013 03:26
Show Gist options
  • Save ytnobody/6419435 to your computer and use it in GitHub Desktop.
Save ytnobody/6419435 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Test::More;
use Plack::Builder;
use Plack::Test;
use HTTP::Request::Common;
my $app = sub { [200,[],['Hello, World']] };
my $wrapped = builder {
enable 'SimpleContentFilter', filter => sub { s/Hello/Welcome/g; };
$app;
};
test_psgi $wrapped, sub {
my $cb = shift;
my $res = $cb->(GET '/');
ok $res->is_success;
is $res->content, 'Welcome, World';
};
done_testing;
@ytnobody
Copy link
Author

ytnobody commented Sep 3, 2013

I got failure in this test...

$ prove ./simple_content_filter.t 
./simple_content_filter.t .. 1/? 
#   Failed test at ./simple_content_filter.t line 19.
#          got: 'Hello, World'
#     expected: 'Welcome, World'
# Looks like you failed 1 test of 2.
./simple_content_filter.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 

Test Summary Report
-------------------
./simple_content_filter.t (Wstat: 256 Tests: 2 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=1, Tests=2,  0 wallclock secs ( 0.01 usr  0.01 sys +  0.04 cusr  0.00 csys =  0.06 CPU)
Result: FAIL

@ytnobody
Copy link
Author

ytnobody commented Sep 3, 2013

SimpleContentFilter checks that Content-Type is 'text/*'.
When not matched, content will not be filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment