Skip to content

Commit

Permalink
fixed tests if Business::ISBN is install
Browse files Browse the repository at this point in the history
  • Loading branch information
barbie committed Aug 31, 2013
1 parent 0d77dbe commit 3f87dfe
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Revision history for Perl distribution WWW::Scraper::ISBN
=========================================================

- fixed tests if Business::ISBN is installed.
- added done_testing() due to test differences.
- Test::Simple v0.88 needed for done_testing.

0.27 2013-08-27
- American dates!
- updated prerequisities.
Expand Down
2 changes: 1 addition & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test" : {
"requires": {
"IO::File": "0",
"Test::More": "0.70"
"Test::More": "0.88"
},
"recommends": {
"Test::CPAN::Meta": "0",
Expand Down
2 changes: 1 addition & 1 deletion META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ recommends:
Test::Pod::Coverage: 0.08
build_requires:
IO::File: 0
Test::More: 0.70
Test::More: 0.88

provides:
WWW::Scraper::ISBN:
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ WriteMakefile(

# build/test prereqs
'IO::File' => '0',
'Test::More' => '0.70'
'Test::More' => '0.88'

}
);
2 changes: 1 addition & 1 deletion lib/WWW/Scraper/ISBN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub reset_drivers {

sub search {
my ($self,$isbn) = @_;

if($business_isbn_loaded) {
my $isbn_object = Business::ISBN->new($isbn);
croak("Invalid ISBN specified.\n") unless($isbn_object && $isbn_object->is_valid);
Expand Down
36 changes: 30 additions & 6 deletions t/10object.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ use strict;

use lib qw(t/lib);

use Test::More tests => 18;
use Test::More;
use WWW::Scraper::ISBN;

# Can we create the object?

my $scraper = WWW::Scraper::ISBN->new();
isa_ok($scraper,'WWW::Scraper::ISBN');
my $scraper2 = $scraper->new();
isa_ok($scraper2,'WWW::Scraper::ISBN');

# can we handle drivers?

my @drivers = $scraper->drivers("Test");
is(@drivers,1);
is($drivers[0],'Test');
@drivers = $scraper->reset_drivers();
is(@drivers,0);

# Can we search for a vslid ISBN, with no driver?

my $isbn = "123456789X";
my $record;
eval { $record = $scraper->search($isbn) };
Expand All @@ -26,6 +32,8 @@ like($@,qr/No search drivers specified/);
is(@drivers,1);
is($drivers[0],'Test');

# Can we search for a vslid ISBN, with driver?

eval { $record = $scraper->search($isbn) };
is($@,'');
isa_ok($record,'WWW::Scraper::ISBN::Record');
Expand All @@ -35,10 +43,26 @@ is($b->{isbn},'123456789X');
is($b->{title},'test title');
is($b->{author},'test author');

# Can we search for an invalid ISBN?

eval "use Business::ISBN";
my $business_isbn_loaded = ! $@;

$isbn = "1234567890";
$record = undef;
eval { $record = $scraper->search($isbn) };
is($@,'');
isa_ok($record,'WWW::Scraper::ISBN::Record');
is($record->found,0);
$b = $record->book;
is($b,undef);

# Note: validation is different if Business::ISBN is installed

if($business_isbn_loaded) {
like($@,qr/Invalid ISBN specified/);
isa_ok($record,undef);
} else {
is($@,'');
isa_ok($record,'WWW::Scraper::ISBN::Record');
is($record->found,0);
$b = $record->book;
is($b,undef);
}

done_testing();

0 comments on commit 3f87dfe

Please sign in to comment.