Le jeudi 06 mars 2003 à 10:43, Andy Lester écrivait:
> >For example, we use it at work for testing our web applications. The
> >slightly overly-secure server we use for developing can not see the
> >Internet, but it can test on localhost or other internal
> >servers. (There's a local CPAN mirror and other such things to make it
> >bearable).
> 
> I've created RT ticket #2185.  If anyone would like to implement this 
> and submit the patch to me, I'd appreciate it.  I'm fresh out of tuits 
> for implementing daemons on the fly.

Here are (very) simple SKIP blocks with a basic web_ok() function.

One could go one step further and put sample pages in t/, as well as
a basic HTTP::Daemon script that would return them when asked for,
and 404 when they are not found.

I'll try to post a set of dummy_*.t files (reproducing the tests in your
own test suite) doing just that in a few days (no promise, though).

Then testing the module would not depend on the web at all.


    -- Philippe


Only in WWW-Mechanize/t: Utils.pm

package main;

# check that the web connection is working
sub web_ok {
    my $ua = LWP::UserAgent->new( env_proxy => 1 );
    my $res =
      $ua->request(
        HTTP::Request->new( GET => 'http://www.google.com/intl/en/' ) );
    return $res->is_success;
}

1;

diff -ru WWW-Mechanize-0.37/t/click.t WWW-Mechanize/t/click.t
--- WWW-Mechanize-0.37/t/click.t        2003-03-04 22:06:03.000000000 +0100
+++ WWW-Mechanize/t/click.t     2003-03-06 18:21:12.000000000 +0100
@@ -1,6 +1,7 @@
 use warnings;
 use strict;
 use Test::More tests => 8;
+use t::Utils;
 
 BEGIN {
     use_ok( 'WWW::Mechanize' );
@@ -9,6 +10,9 @@
 my $t = WWW::Mechanize->new();
 isa_ok( $t, 'WWW::Mechanize', 'Created the object' );
 
+SKIP: {
+    skip "Web does not seem to work", 6 unless web_ok();
+
 my $response = $t->get( "http://www.google.com/intl/en/";);
 isa_ok( $response, 'HTTP::Response', 'Got back a response' );
 ok( $response->is_success, 'Got google' ) or die "Can't even fetch google";
@@ -21,3 +25,5 @@
 ok( $response->is_success, "Can click 'btnG' ('Google Search' button)");
 
 like($t->content, qr/foo\s?fighters/i, "Found 'Foo Fighters'");
+
+}

diff -ru WWW-Mechanize-0.37/t/follow.t WWW-Mechanize/t/follow.t
--- WWW-Mechanize-0.37/t/follow.t       2003-02-04 17:29:18.000000000 +0100
+++ WWW-Mechanize/t/follow.t    2003-03-06 18:20:24.000000000 +0100
@@ -2,6 +2,7 @@
 use strict;
 use Test::More tests => 14;
 use constant START => 'http://www.google.com/intl/en/';
+use t::Utils;
 
 BEGIN {
     use_ok( 'WWW::Mechanize' );
@@ -11,6 +12,9 @@
 isa_ok( $agent, 'WWW::Mechanize', 'Created object' );
 $agent->quiet(1);
 
+SKIP: {
+    skip "Web does not seem to work", 12 unless web_ok();
+
 my $response = $agent->get( START );
 ok( $response->is_success, 'Got some page' );
 is( $agent->uri, START, 'Got Google' );
@@ -30,3 +34,5 @@
 
 ok($agent->back(), "Can still go back");
 is( $agent->uri, START, 'Back at the start page again' );
+
+}

diff -ru WWW-Mechanize-0.37/t/form.t WWW-Mechanize/t/form.t
--- WWW-Mechanize-0.37/t/form.t 2003-02-04 17:44:46.000000000 +0100
+++ WWW-Mechanize/t/form.t      2003-03-06 18:21:50.000000000 +0100
@@ -3,6 +3,7 @@
 use warnings;
 use strict;
 use Test::More tests => 14;
+use t::Utils;
 
 use constant START => 'http://www.google.com/intl/en/';
 
@@ -13,6 +14,10 @@
 my $t = WWW::Mechanize->new();
 isa_ok( $t, 'WWW::Mechanize' );
 $t->quiet(1);
+
+SKIP: {
+    skip "Web does not seem to work", 12 unless web_ok();
+
 my $response = $t->get(START);
 ok( $response->is_success, "Got a page" ) or die "Can't even get google";
 is( $t->uri, START, 'Got Google' );
@@ -37,3 +42,5 @@
 my $form_f = $t->form('f');
 ok( $form_f );
 is( $form_f, $form_name_f );
+
+}

diff -ru WWW-Mechanize-0.37/t/get.t WWW-Mechanize/t/get.t
--- WWW-Mechanize-0.37/t/get.t  2003-03-04 22:01:14.000000000 +0100
+++ WWW-Mechanize/t/get.t       2003-03-06 18:20:40.000000000 +0100
@@ -1,6 +1,7 @@
 use warnings;
 use strict;
 use Test::More tests => 27;
+use t::Utils;
 
 BEGIN {
     use_ok( 'WWW::Mechanize' );
@@ -9,6 +10,9 @@
 my $agent = WWW::Mechanize->new;
 isa_ok( $agent, 'WWW::Mechanize', 'Created object' );
 
+SKIP: {
+    skip "Web does not seem to work", 25 unless web_ok();
+
 ok($agent->get("http://www.google.com/intl/en/";)->is_success, "Get google webpage");
 isa_ok($agent->uri, "URI", "Set uri");
 isa_ok($agent->req, 'HTTP::Request', "req should be a HTTP::Request");
@@ -39,3 +43,5 @@
 
 ok( $agent->get( "http://www.google.com/images/logo.gif"; )->is_success, "Got the 
logo" );
 ok( !$agent->is_html );
+
+}

diff -ru WWW-Mechanize-0.37/t/page_stack.t WWW-Mechanize/t/page_stack.t
--- WWW-Mechanize-0.37/t/page_stack.t   2002-10-24 05:52:55.000000000 +0200
+++ WWW-Mechanize/t/page_stack.t        2003-03-06 18:22:04.000000000 +0100
@@ -1,6 +1,7 @@
 use warnings;
 use strict;
 use Test::More tests => 9;
+use t::Utils;
 
 BEGIN {
     use_ok( 'WWW::Mechanize' );
@@ -9,6 +10,9 @@
 my $t = WWW::Mechanize->new;
 isa_ok( $t, 'WWW::Mechanize', 'Created object' );
 
+SKIP: {
+    skip "Web does not seem to work", 7 unless web_ok();
+
 ok( $t->get("http://www.google.com/intl/en/";)->is_success, "Got Google" );
 is(scalar @{$t->{page_stack}}, 0, "Page stack starts empty");
 $t->_push_page_stack();
@@ -21,3 +25,4 @@
 is(scalar @{$t->{page_stack}}, 0, "Popped item from page stack");
 $t->_pop_page_stack();
 is(scalar @{$t->{page_stack}}, 0, "Can't pop beyond end of page stack");
+}


-- 
 Philippe "BooK" Bruhat

 When you wander near evil, Security is only a function of foolishness...
                                    (Moral from Groo The Wanderer #21 (Epic))

Reply via email to