Last active
August 29, 2015 14:10
-
-
Save Wu-Wu/2340443ce02b9cb29f39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Test::Spec; | |
{ | |
package Foo::Bar; | |
use LWP::UserAgent; | |
sub new { | |
my $self = { | |
ua => LWP::UserAgent->new, | |
}; | |
bless $self, shift; | |
return $self; | |
} | |
sub get_url { | |
my ( $self, $uri ) = @_; | |
return $self->{ua}->get( $uri ); | |
}; | |
1; | |
} | |
describe "get_url()" => sub { | |
my ( $foo ); | |
before all => sub { | |
$foo = Foo::Bar->new; | |
}; | |
describe "for google.com" => sub { | |
before all => sub { | |
LWP::UserAgent->expects( 'get' )->returns( 'content for google.com' ); | |
}; | |
it "should match content" => sub { | |
is( $foo->get_url( 'google.com' ), 'content for google.com' ); | |
}; | |
}; | |
describe "for yandex.ru" => sub { | |
before all => sub { | |
LWP::UserAgent->expects( 'get' )->returns( 'content for yandex.ru' ); | |
}; | |
it "should match content" => sub { | |
is( $foo->get_url( 'yandex.ru' ), 'content for yandex.ru' ); | |
}; | |
}; | |
describe "for any" => sub { | |
before all => sub { | |
LWP::UserAgent->stubs( 'get' => sub { | |
my ( $this, $uri ) = @_; | |
return 'content for ' . $uri; | |
}); | |
}; | |
it "should match for vk.com" => sub { | |
is( $foo->get_url( 'vk.com' ), 'content for vk.com' ); | |
}; | |
it "should match for facebook.com" => sub { | |
is( $foo->get_url( 'facebook.com' ), 'content for facebook.com' ); | |
}; | |
}; | |
}; | |
runtests unless caller; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment