Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b67adda877
Fetching contributors…

Cannot retrieve contributors at this time

75 lines (52 sloc) 1.945 kb
use strict;
use warnings;
use Test::More qw(no_plan);
use IO::All;
BEGIN {
use_ok aliased => 'IronMunger::PlaggerLoader';
}
my @names = ('Jess Robinson', 'Justin DeVuyst');
my @files = ('my_Jess_Robinson.csv', 'my_Justin_DeVuyst.csv');
ok(my $loader = PlaggerLoader->new(dir => 't/csv'), 'build loader');
my @target = $loader->_target_files;
cmp_ok(@target, '==', 2, '2 files in CSV directory');
is_deeply(
[ sort map { ($_->splitpath)[-1] } @target ], \@files,
'filenames ok'
);
{
my %args = (url => 'http://foo.com', at => '2008-04-06T12:00:00');
ok(my $post = $loader->_expand_post(\%args), 'Expand post constructs object');
foreach my $key (sort keys %args) {
is($post->$key, $args{$key}, "Attribute ${key} ok");
}
}
my @postspecs = map
+{
url => 'http://jdv79.blogspot.com/2009/05/testable-v007.html',
at => $_,
}, qw(2009-05-13T02:45:00 2009-05-14T16:00:00);
my $jdv_file = io('t/csv/my_Justin_DeVuyst.csv');
my $specs = $loader->_expand_postspecs_from_file($jdv_file);
#expand_postspecs reads in file order
is_deeply($specs, \@postspecs, 'Post specs from file ok');
my $posts = $loader->_expand_posts_from_file($jdv_file);
#expand_posts is sorted in newest first by 'at'
@postspecs = sort{ $b->{at} cmp $a->{at} } @postspecs;
cmp_ok(scalar(@$posts), '==', scalar(@postspecs), 'Right number of posts');
foreach my $i (0, 1) {
my %spec = %{$postspecs[$i]};
my $post = $posts->[$i];
foreach my $key (sort keys %spec) {
is($post->$key, $spec{$key}, "Attribute ${key} ok for post ${i}");
}
}
my $jdv = $loader->_expand_monger($jdv_file);
is($jdv->name, 'Justin DeVuyst', 'Name correct');
ok(!$jdv->has_nick, 'No nickname');
cmp_ok(@{$jdv->posts}, '==', 2, '2 posts loaded');
my @mongers = sort { $a->name cmp $b->name } $loader->mongers;
cmp_ok(scalar(@mongers), '==', 2, '2 mongers loaded');
foreach my $i (0, 1) {
is($mongers[$i]->name, $names[$i], $names[$i].' loaded');
}
Jump to Line
Something went wrong with that request. Please try again.