=================================================================== RCS file: /cvs/todotxt/Text-Todo/t/dudelicious.t,v retrieving revision 1.4 retrieving revision 1.7 diff -u -r1.4 -r1.7 --- todotxt/Text-Todo/t/dudelicious.t 2010/04/30 02:24:06 1.4 +++ todotxt/Text-Todo/t/dudelicious.t 2010/04/30 07:18:33 1.7 @@ -1,4 +1,5 @@ #!perl +# $AFresh1: dudelicious.t,v 1.6 2010/04/30 01:43:14 andrew Exp $ use Test::More; # tests => 3; use strict; @@ -8,10 +9,11 @@ use File::Copy qw/ cp /; use File::Spec; +my $have_test_json = 1; + BEGIN { eval "use Test::Mojo"; plan skip_all => "Test::Mojo required for testing dudelicious" if $@; - } my $todo_dir = tempdir( 'todo-XXXXXXXXX', CLEANUP => 1, TMPDIR => 1 ); @@ -29,48 +31,44 @@ my $t = Test::Mojo->new; +my @exts = ( q{}, '.html', '.txt', '.json' ); foreach my $p ( '/', - '/l/todo1', - '/l/todo1.html', - '/l/todo1.txt', - '/l/todo1.json', - '/l/todo1/e/1', - '/l/todo1/e/1.html', - '/l/todo1/e/1.json', - '/l/todo1/t', - '/l/todo1/t.txt', - '/l/todo1/t.json', -) { - my ($volume, $directories, $file) = File::Spec->splitpath($p); + ( map { '/l/todo1' . $_ } @exts ), + ( map { '/l/todo1/e/1' . $_ } @exts ), + ( map { '/l/todo1/e/4' . $_ } @exts ), + ( map { '/l/todo1/t' . $_ } @exts ), + ( map { '/l/todo1/t/project' . $_ } @exts ), + ( map { '/l/todo1/t/context' . $_ } @exts ), + ) +{ + my ( $volume, $directories, $file ) = File::Spec->splitpath($p); + $file ||= 'index.html'; + $file .= '.html' if $file !~ /\.[^.]+$/xms; - if ($file !~ /\.[^.]+$/xms) { - $file .= '.html'; - } + my $f = File::Spec->catfile( 't', 'dudelicious', $volume, $directories, + $file ); +SKIP: { + skip "$f does not exist", 3 if !-e $f; + diag("Get [$f] from [$p]"); - my $f = File::Spec->catfile( 't', 'dudelicious', $volume, $directories, - $file); + open my $fh, '<', $f or die $f . ': ' . $!; + my $content = do { local $/; <$fh> }; + close $fh; - SKIP: { - skip "$f does not exist", 3 if ! -e $f; - diag( "Getting [$f] from [$p]" ); - $t->get_ok($p)->status_is(200)->content_is( slurp( $f ) ); + if ( $f =~ /\.json$/xms ) { + $t->get_ok($p)->status_is(200) + ->json_content_is( Mojo::JSON->decode($content), + 'Check JSON content' ); + } + else { + $t->get_ok($p)->status_is(200) + ->content_is( $content, 'Check content' ); + } } } done_testing(); - - -sub slurp { - my ($file) = @_; - - local $/; - open my $fh, '<', $file or die $file . ': ' . $!; - my $content = <$fh>; - close $fh; - - return $content; -}