[Rt-commit] rt branch, watching-tool, updated. rt-3.8.8-750-ge6da484
Shawn Moore
sartak at bestpractical.com
Fri Sep 10 16:41:58 EDT 2010
The branch, watching-tool has been updated
via e6da4841fad6c8a57c6cbcea1d75975965c205a5 (commit)
from 0996d70045bb5d67bb9400bdc8ce869c99b927bb (commit)
Summary of changes:
sbin/rt-test-dependencies.in | 2 +-
t/web/watching-queues.t | 99 +++++++++++++++++------------------------
2 files changed, 42 insertions(+), 59 deletions(-)
- Log -----------------------------------------------------------------
commit e6da4841fad6c8a57c6cbcea1d75975965c205a5
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Sep 10 16:44:16 2010 -0400
Replace Test::XPath with Web::Scraper
The resulting code is shorter, human-friendly, and uses CSS
selectors instead of XPath :)
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index d94e727..547ee9e 100755
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -271,7 +271,7 @@ Test::Builder 0.77 # needed to fix TODO test
Test::MockTime
HTTP::Server::Simple::Mason 0.13
Log::Dispatch::Perl
-Test::XPath
+Web::Scraper
.
$deps{'FASTCGI'} = [ text_to_hash( << '.') ];
diff --git a/t/web/watching-queues.t b/t/web/watching-queues.t
index 95720da..c90b834 100644
--- a/t/web/watching-queues.t
+++ b/t/web/watching-queues.t
@@ -1,8 +1,8 @@
#!/usr/bin/perl -w
use strict;
-use RT::Test tests => 70;
-use Test::XPath;
+use RT::Test tests => 45;
+use Web::Scraper;
my ($baseurl, $m) = RT::Test->started_ok;
ok $m->login, 'logged in';
@@ -12,6 +12,19 @@ $other_queue->Create(
Name => 'Fancypants',
);
+my $watching = scraper {
+ process "li.queue-roles", 'queues[]' => scraper {
+ # trim the queue name
+ process 'span.queue-name', name => sub {
+ my $name = shift->as_text;
+ $name =~ s/^\s*//;
+ $name =~ s/\s*$//;
+ return $name;
+ };
+ process "li.queue-role", 'roles[]' => 'TEXT';
+ };
+};
+
diag "check watching page" if $ENV{'TEST_VERBOSE'};
{
$m->follow_link( text => 'Tools' );
@@ -21,8 +34,7 @@ diag "check watching page" if $ENV{'TEST_VERBOSE'};
$m->content_contains('You are not watching any queues.');
- my $tx = new_tx($m->content);
- $tx->not_ok('//ul[contains(@class,"queue-list")]', 'no queue list when watching nothing');
+ is_deeply($watching->scrape($m->content), {});
}
diag "add self as AdminCc on General" if $ENV{'TEST_VERBOSE'};
@@ -73,16 +85,13 @@ diag "check watching page" if $ENV{'TEST_VERBOSE'};
$m->content_lacks('You are not watching any queues.');
- my $tx = new_tx($m->content);
- $tx->ok('//ul[contains(@class,"queue-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-roles")])', 1, 'only one queue');
- $_->ok('.//li[contains(@class,"queue-roles")]', sub {
- $_->like('.//span[contains(@class,"queue-name")][text()]', qr/^\s*General\s*$/, 'correct queue');
- $_->ok('.//ul[contains(@class,"queue-role-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-role")])', 1, 'only one role');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/^\s*AdminCc\s*$/, 'correct role');
- });
- });
+ is_deeply($watching->scrape($m->content), {
+ queues => [
+ {
+ name => 'General',
+ roles => ['AdminCc'],
+ },
+ ],
});
}
@@ -134,17 +143,13 @@ diag "check watching page" if $ENV{'TEST_VERBOSE'};
$m->content_lacks('You are not watching any queues.');
- my $tx = new_tx($m->content);
- $tx->ok('//ul[contains(@class,"queue-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-roles")])', 1, 'only one queue');
- $_->ok('.//li[contains(@class,"queue-roles")]', sub {
- $_->like('.//span[contains(@class,"queue-name")][text()]', qr/^\s*General\s*$/, 'correct queue');
- $_->ok('.//ul[contains(@class,"queue-role-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-role")])', 2, 'two roles');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/AdminCc/, 'list includes AdminCc');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/(?<!Admin)Cc/, 'list includes Cc too');
- });
- });
+ is_deeply($watching->scrape($m->content), {
+ queues => [
+ {
+ name => 'General',
+ roles => ['Cc', 'AdminCc'],
+ },
+ ],
});
}
@@ -194,39 +199,17 @@ diag "check watching page" if $ENV{'TEST_VERBOSE'};
$m->content_lacks('You are not watching any queues.');
- my $tx = new_tx($m->content);
- $tx->ok('//ul[contains(@class,"queue-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-roles")])', 2, 'two queues');
-
- $_->ok('.//li[contains(@class,"queue-roles")][contains(.//span[contains(@class,"queue-name")][text()],"General")]', sub {
- $_->like('.//span[contains(@class,"queue-name")][text()]', qr/^\s*General\s*$/, 'correct queue');
- $_->ok('.//ul[contains(@class,"queue-role-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-role")])', 2, 'two roles');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/AdminCc/, 'list includes AdminCc');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/(?<!Admin)Cc/, 'list includes Cc too');
- });
- });
-
- $_->ok('.//li[contains(@class,"queue-roles")][contains(.//span[contains(@class,"queue-name")][text()],"Fancypants")]', sub {
- $_->like('.//span[contains(@class,"queue-name")][text()]', qr/^\s*Fancypants\s*$/, 'correct queue');
- $_->ok('.//ul[contains(@class,"queue-role-list")]', sub {
- $_->is('count(.//li[contains(@class,"queue-role")])', 1, 'one roles');
- $_->like('.//li[contains(@class,"queue-role")][text()]', qr/^\s*AdminCc\s*$/, 'correct role');
- });
- });
+ is_deeply($watching->scrape($m->content), {
+ queues => [
+ {
+ name => 'Fancypants',
+ roles => ['AdminCc'],
+ },
+ {
+ name => 'General',
+ roles => ['Cc', 'AdminCc'],
+ },
+ ],
});
}
-sub new_tx {
- my $content = shift;
-
- # need to recover from embedded javascript using <!-- -->
- my $tx = Test::XPath->new(
- xml => $content,
- is_html => 1,
- options => { recover => 1 },
- );
-
- return $tx;
-}
-
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list