File: README

package info (click to toggle)
libtest-www-declare-perl 0.01-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 180 kB
  • ctags: 124
  • sloc: perl: 1,654; makefile: 41
file content (119 lines) | stat: -rw-r--r-- 4,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
SYNOPSIS
        use Test::WWW::Declare tests => 3;
        use Your::Web::App::Test;

        Your::Web::App::Test->start_server;

        session 'testuser' => run {
            flow 'log in and out' => check {
                flow 'log in' => check {
                    get 'http://localhost/';
                    fill form 'login' => {
                        username => 'testuser',
                        password => 'drowssap',
                    };
                    content should contain 'log out';
                };

                flow 'log out' => check {
                    get 'http://localhost/';
                    click href 'log out';
                };
            };
        };

DESCRIPTION
    Often in web apps, tests are very dependent on the state set up by
    previous tests. If one test fails (e.g. "follow the link to the admin
    page") then it's likely there will be many more failures. This module
    aims to alleviate this problem, as well as provide a nicer interface to
    Test::WWW::Mechanize.

    The central idea is that of "flow". Each flow is a sequence of commands
    ("fill in this form") and assertions ("content should contain
    'testuser'"). If any of these commands or assertions fail then the flow
    is aborted. Only that one failure is reported to the test harness and
    user. Flows may also contain other flows. If an inner flow fails, then
    the outer flow fails as well.

FLOWS AND SESSIONS
  session NAME => run { CODE }
    Sessions are a way of associating a set of flows with a WWWW::Mechanize
    instance. A session is mostly equivalent with a user interacting with
    your web app.

    Within a session, every command ("get", "click link", etc) is operating
    on that session's WWW::Mechanize instance. You may have multiple
    sessions in one test file. Two sessions with the same name are in fact
    the same session. 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/;
                };
            };
        };

  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.

COMMANDS
  get URL
  click button
  click href
  follow_link
  fill form NAME => {FIELD1 => VALUE1, FIELD2 => VALUE2}
ASSERTIONS
    Every assertion has two parts: a subject and a verb.

  SUBJECTS
   content
   title
   url
  VERBS
   should(nt) (caselessly) match REGEX
   should(nt) (caselessly) contain STRING
   should(nt) (caselessly) lack STRING
   should(nt) (caselessly) equal STRING
SUBCLASSING
    One of the goals of this module is to let you subclass it to provide
    extra features, such as automatically logging in a user each time a
    session is created.

CAVEATS
    If you fail any tests, then the actual number of tests run may be fewer
    than you have in your file. This is because when a flow fails, it
    immediately aborts the rest of its body (which may include other flows).
    So if you're setting the number of tests based on how many ran, make
    sure that all tests passed.

BUGS
    Hopefully few. We'd like to know about any of them. Please report them
    to "bug-test-www-declare@rt.cpan.org".

SEE ALSO
    Test::WWW::Mechanize, Jifty.

MAINTAINER
    Shawn M Moore "<sartak@bestpractical.com>"

ORIGINAL AUTHOR
    Jesse Vincent "<jesse@bestpractical.com>"

COPYRIGHT
    Copyright 2007 Best Practical Solutions, LLC

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.