浏览代码

Merge pull request #171 from gempesaw/skip-all-if-mocks-are-missing

Daniel Gempesaw 11 年之前
父节点
当前提交
56abd09d10
共有 8 个文件被更改,包括 36 次插入43 次删除
  1. 1 0
      .gitignore
  2. 4 6
      t/01-driver.t
  3. 2 4
      t/02-webelement.t
  4. 0 1
      t/10-switch-to-window.t
  5. 2 4
      t/Firefox-Profile.t
  6. 2 4
      t/Test-Selenium-Remote-Driver-google.t
  7. 0 1
      t/error.t
  8. 25 23
      t/lib/TestHarness.pm

+ 1 - 0
.gitignore

@@ -9,3 +9,4 @@ cover_db
 .build
 .build
 Selenium-Remote-Driver-*
 Selenium-Remote-Driver-*
 .prove
 .prove
+_prove

+ 4 - 6
t/01-driver.t

@@ -14,11 +14,9 @@ use FindBin;
 use lib $FindBin::Bin . '/lib';
 use lib $FindBin::Bin . '/lib';
 use TestHarness;
 use TestHarness;
 
 
-my $harness = TestHarness->new(
+my %selenium_args = %{ TestHarness->new(
     this_file => $FindBin::Script
     this_file => $FindBin::Script
-);
-my %selenium_args = %{ $harness->base_caps };
-$harness->skip_all_unless_mocks_exist;
+)->base_caps };
 
 
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $website = 'http://localhost:63636';
 my $website = 'http://localhost:63636';
@@ -409,9 +407,9 @@ BASE_URL: {
                 spec => {
                 spec => {
                     get =>
                     get =>
                       sub { my ( undef, $params ) = @_; return $params->{url} }
                       sub { my ( undef, $params ) = @_; return $params->{url} }
-                },
+                  },
                 mock_cmds => $mock_commands
                 mock_cmds => $mock_commands
-              ),
+            ),
             commands => $mock_commands,
             commands => $mock_commands,
         );
         );
         my $got = $base_url_driver->get($test->{url});
         my $got = $base_url_driver->get($test->{url});

+ 2 - 4
t/02-webelement.t

@@ -9,11 +9,9 @@ use FindBin;
 use lib $FindBin::Bin . '/lib';
 use lib $FindBin::Bin . '/lib';
 use TestHarness;
 use TestHarness;
 
 
-my $harness = TestHarness->new(
+my %selenium_args = %{ TestHarness->new(
     this_file => $FindBin::Script
     this_file => $FindBin::Script
-);
-my %selenium_args = %{ $harness->base_caps };
-$harness->skip_all_unless_mocks_exist;
+)->base_caps };
 
 
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $website = 'http://localhost:63636';
 my $website = 'http://localhost:63636';

+ 0 - 1
t/10-switch-to-window.t

@@ -18,7 +18,6 @@ my %selenium_args = (
     javascript     => 1,
     javascript     => 1,
     %{ $harness->base_caps }
     %{ $harness->base_caps }
 );
 );
-$harness->skip_all_unless_mocks_exist;
 
 
 plan tests => 9;
 plan tests => 9;
 
 

+ 2 - 4
t/Firefox-Profile.t

@@ -17,11 +17,9 @@ use FindBin;
 use lib $FindBin::Bin . '/lib';
 use lib $FindBin::Bin . '/lib';
 use TestHarness;
 use TestHarness;
 
 
-my $harness = TestHarness->new(
+my %selenium_args = %{ TestHarness->new(
     this_file => $FindBin::Script
     this_file => $FindBin::Script
-);
-my %selenium_args = %{ $harness->base_caps };
-$harness->skip_all_unless_mocks_exist;
+)->base_caps };
 
 
 my $fixture_dir = $FindBin::Bin . '/www/';
 my $fixture_dir = $FindBin::Bin . '/www/';
 
 

+ 2 - 4
t/Test-Selenium-Remote-Driver-google.t

@@ -9,11 +9,9 @@ use FindBin;
 use lib $FindBin::Bin . '/lib';
 use lib $FindBin::Bin . '/lib';
 use TestHarness;
 use TestHarness;
 
 
-my $harness = TestHarness->new(
+my %selenium_args = %{ TestHarness->new(
     this_file => $FindBin::Script
     this_file => $FindBin::Script
-);
-my %selenium_args = %{ $harness->base_caps };
-$harness->skip_all_unless_mocks_exist;
+)->base_caps };
 
 
 # Try to find
 # Try to find
 my $t = Test::Selenium::Remote::Driver->new(
 my $t = Test::Selenium::Remote::Driver->new(

+ 0 - 1
t/error.t

@@ -7,7 +7,6 @@ use Test::Exception;
 use Test::LWP::UserAgent;
 use Test::LWP::UserAgent;
 use IO::Socket::INET;
 use IO::Socket::INET;
 
 
-
 BEGIN: {
 BEGIN: {
     unless (use_ok('Selenium::Remote::Driver')) {
     unless (use_ok('Selenium::Remote::Driver')) {
         BAIL_OUT("Couldn't load Selenium::Remote::Driver");
         BAIL_OUT("Couldn't load Selenium::Remote::Driver");

+ 25 - 23
t/lib/TestHarness.pm

@@ -8,11 +8,23 @@ use Test::More;
 
 
 =head1 SYNOPSIS
 =head1 SYNOPSIS
 
 
-    my $harness = TestHarness->new(
+    my %selenium_args = %{ TestHarness->new(
         this_file => $FindBin::Script
         this_file => $FindBin::Script
-    );
-    my %selenium_args = %{ $harness->base_caps };
-    $harness->skip_all_unless_mocks_exist;
+    )->base_caps };
+
+=head1 DESCRIPTION
+
+A setup class for all the repetitive things we need to do before
+running tests. First, we're deciding whether the test is in C<record>
+or C<replay> mode. If we're recording, we'll end up writing all the
+HTTP request/response pairs out to L</mock_file>. If we're replaying,
+we'll look for our OS-appropriate mock_file and try to read from it.
+
+After we figure that out, we can instantiate our
+Mock::RemoteConnection with the proper constructor arguments and
+return that as our base_args for use in the tests! Finally, on
+destruction, if we're recording, we make sure to dump out all of the
+request/response pairs to the mock_file.
 
 
 =attr this_file
 =attr this_file
 
 
@@ -103,28 +115,18 @@ has mock_file => (
         my $test_name = lc($self->calling_file);
         my $test_name = lc($self->calling_file);
         $test_name =~ s/\.t$//;
         $test_name =~ s/\.t$//;
 
 
-        return $mock_folder . $test_name . '-mock-' . $self->os . '.json';
-    }
-);
+        my $mock_file = $mock_folder . $test_name . '-mock-' . $self->os . '.json';
 
 
-sub skip_all_unless_mocks_exist {
-    my ($self) = @_;
-    unless ($self->mocks_exist_for_platform) {
-        plan skip_all => "Mocking of tests is not been enabled for this platform";
-    }
-}
+        # If we're replaying, we need a mock to read from. Otherwise,
+        # we can't do anything
+        if (not $self->record) {
+            plan skip_all => "Mocking of tests is not been enabled for this platform"
+              unless -e $mock_file;
+        }
 
 
-sub mocks_exist_for_platform {
-    my ($self) = @_;
-    if ($self->record) {
-        return 1;
+        return $mock_file;
     }
     }
-    else {
-        # When we're replaying a test, we need recordings to be able
-        # to do anything
-        return -e $self->mock_file;
-    }
-}
+);
 
 
 sub DEMOLISH {
 sub DEMOLISH {
     my ($self) = @_;
     my ($self) = @_;