Test-WWW-Declare

 view release on metacpan or  search on metacpan

lib/Test/WWW/Declare.pm  view on Meta::CPAN

This lets you write code like the following, simplified slightly:

    session 'first user' => run {
        get "$URL/give?task=1&victim=other";
        session 'other user' => run {
            get "$URL/tasks";
            content should match qr/task 1/;

            # this is the same session/mech as the outermost 'first user'
            session 'first user' => run {
                get "$URL/tasks";
                content shouldnt match qr/task 1/;
            };
        };
    };

=head2 flow NAME => check { CODE }

A flow encompasses a single test. As described above, each flow is a sequence
of commands, assertions, and other flows. If any of the components of a flow
fail, the rest of the flow is aborted and one or more test failures are
reported to the test harness.

=head1 COMMANDS

=head2 get URL

=head2 click button

=head2 click href

=head2 follow_link

=head2 fill form NAME => {FIELD1 => VALUE1, FIELD2 => VALUE2}

=head1 ASSERTIONS

Every assertion has two parts: a subject and a verb.

=head2 SUBJECTS

=head3 content

=head3 title

=head3 url

=head2 VERBS

=head3 should(nt) (caselessly) match REGEX

=head3 should(nt) (caselessly) contain STRING

=head3 should(nt) (caselessly) lack STRING

=head3 should(nt) (caselessly) equal STRING

=cut

# DSLey functions
sub to($) { return $_[0] }

sub _args {
    my $args = shift;
    return $args if ref($args) eq 'HASH';
    return {expected => $args};
}

sub should ($) {
    return _args(shift);
}

sub shouldnt ($) {
    my $args = _args(shift);
    $args->{negative} = 1;
    return $args;
}

sub match ($) {
    my $args = _args(shift);
    $args->{match} = 'regex';
    return $args;
}

sub equal ($) {
    my $args = _args(shift);
    $args->{match} = 'equality';
    return $args;
}

sub contain ($) {
    my $args = _args(shift);
    $args->{match} = 'index';
    return $args;
}

sub lack ($) {
    my $args = _args(shift);
    $args->{match} = 'index';
    $args->{negative} = 1;
    return $args;
}

sub caselessly ($) {
    my $args = _args(shift);
    $args->{case_insensitive} = 1;
    return $args;
}

sub check (&) {
    my $coderef = shift;

    return $coderef;
}

sub run (&) {
    my $coderef = shift;

    return $coderef;
}



( run in 2.272 seconds using v1.01-cache-2.11-cpan-364913b4093 )