Skip to content

Commit a4fa22a

Browse files
committed
Address review commentary, also shave 1s off the test :)
1 parent eae31cc commit a4fa22a

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

t/04-commands-implemented.t

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,30 @@ use warnings;
44
use Test::More tests => 3 + 1;
55
use Test::NoWarnings;
66

7-
# Assume we're not using dzil test unless we're doing that
8-
if( !grep { index( $_, ".build" ) != -1 } @INC ) {
9-
require Cwd;
10-
require File::Basename;
11-
push( @INC, File::Basename::dirname(Cwd::abs_path(__FILE__)) . "/../lib" );
12-
}
13-
14-
require_ok( "Selenium::Remote::Commands" ) || die;
7+
require_ok( "Selenium::Remote::Commands" ) || die "Module couldn't be loaded, can't continue with testing!";
158

169
subtest "All implemented commands are found" => sub {
1710
plan skip_all => "Author tests not required for installation." unless $ENV{'RELEASE_TESTING'};
18-
my $comm = Selenium::Remote::Commands->new->get_cmds;
19-
for my $command (keys %{$comm}) {
20-
my $found_command = 0;
21-
for my $file (
22-
qw{lib/Selenium/Remote/Driver.pm
23-
lib/Selenium/Remote/WebElement.pm
24-
lib/Selenium/Firefox.pm}
25-
) {
26-
open(my $fh, '<', $file) or die "Couldn't open file $file";
27-
for (<$fh>) {
28-
if ( /'?command'?\s*=>\s*'$command'/ or /{'?commands'?}->\{'?$command'?}/) {
29-
pass("find $command");
30-
$found_command = 1;
31-
}
32-
}
33-
}
34-
if (!$found_command && $command !~ /Gecko/) {
35-
fail("find $command");
36-
}
11+
my @cmds2see = keys( %{ Selenium::Remote::Commands->new->get_cmds } );
12+
# You won't find the Gecko command in Selenium::Rmeote::Commands. This is intentional, so remove it from consideration.
13+
@cmds2see = grep { $_ !~ /Gecko/ } @cmds2see;
14+
plan 'tests' => scalar( @cmds2see );
15+
my @files = map { _get_file_contents($_) } qw{lib/Selenium/Remote/Driver.pm lib/Selenium/Remote/WebElement.pm lib/Selenium/Firefox.pm};
16+
for my $command (@cmds2see) {
17+
my $detector = q/['"]?command['"]?\s*[=-]{1}>\s*\{?['"]/ . $command . q/['"]\}?/;
18+
my $found = grep { my $contents = $_; grep { $_ =~ qr/$detector/ } @$contents } @files;
19+
ok( $found, "Found $command" );
3720
}
3821
};
3922

23+
sub _get_file_contents {
24+
my $file = shift;
25+
my @contents;
26+
open(my $fh, '<', $file) or die "Couldn't open file $file";
27+
for (<$fh>) { push( @contents, $_ ) }
28+
return \@contents;
29+
}
30+
4031
subtest "get_params() works as intended" => sub {
4132
no warnings qw{redefine once};
4233
# I know this is somewhat whimsical as an URL, but hey, it is a test.

0 commit comments

Comments
 (0)