dbrady-tourbus 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,134 @@
|
|
1
|
+
= Contact App
|
2
|
+
|
3
|
+
Silly little contact app to show you how to tour a website.
|
4
|
+
|
5
|
+
= Requirements
|
6
|
+
|
7
|
+
In addition to tourbus, you will need Sinatra to run
|
8
|
+
this app.
|
9
|
+
|
10
|
+
sudo gem install sinatra
|
11
|
+
|
12
|
+
= Contact App
|
13
|
+
|
14
|
+
== Start the app
|
15
|
+
|
16
|
+
Once that's working, start the app with "ruby contact_app.rb". Sinatra
|
17
|
+
should start up, and you can now point your browser at
|
18
|
+
http://localhost:4567 to see the app's homepage.
|
19
|
+
|
20
|
+
Pretty humble, I know; just the one link labeled Enter Contacts. Click
|
21
|
+
it to get to the Contact form. Here you can enter a first and last
|
22
|
+
name then click submit.
|
23
|
+
|
24
|
+
The app then shows you that name in last_name, first_name format.
|
25
|
+
That's the whole app. Don't everybody applaud all at once.
|
26
|
+
|
27
|
+
== First Tour
|
28
|
+
|
29
|
+
Still here? Okay, let's tour this website.
|
30
|
+
|
31
|
+
In the tours folder, you will find two files: simple.rb and
|
32
|
+
tourbus.yml. The YAML file just sets the default host to
|
33
|
+
localhost:4567. (Without it, tourbus will default to localhost:3000.
|
34
|
+
You could override this by running tourbus with "-h localhost:4567"
|
35
|
+
every time, but that gets tedious.
|
36
|
+
|
37
|
+
Before we go any farther, let's run tourbus. Leave Sinatra running and
|
38
|
+
open another terminal window. Go into the contact_app folder and just
|
39
|
+
type "tourbus". You should get a screenful of information ending with
|
40
|
+
a happy little banner something like this:
|
41
|
+
|
42
|
+
2009-01-10 12:09:36 TourBus: --------------------------------------------------------------------------------
|
43
|
+
2009-01-10 12:09:36 TourBus: 1 runs: 1x1 of simple
|
44
|
+
2009-01-10 12:09:36 TourBus: All Runners finished.
|
45
|
+
2009-01-10 12:09:36 TourBus: Total Runs: 1
|
46
|
+
2009-01-10 12:09:36 TourBus: Total Passes: 1
|
47
|
+
2009-01-10 12:09:36 TourBus: Total Fails: 0
|
48
|
+
2009-01-10 12:09:36 TourBus: Total Errors: 0
|
49
|
+
2009-01-10 12:09:36 TourBus: Elapsed Time: 0.0131220817565918
|
50
|
+
2009-01-10 12:09:36 TourBus: Speed: 76.207 v/s
|
51
|
+
2009-01-10 12:09:36 TourBus: --------------------------------------------------------------------------------
|
52
|
+
|
53
|
+
== Tourbus Defaults
|
54
|
+
|
55
|
+
Tourbus tries to be sensible; if you don't provide a number of runs or
|
56
|
+
concurrency, it sets them to 1. If you don't choose a tour to run, it
|
57
|
+
runs them all. It looks for tourbus.yml in the current folder,
|
58
|
+
./tours, in ./config (a Rails convention), and in your home folder.
|
59
|
+
(It looks for them in that order, and stops as soon as it finds one.
|
60
|
+
It does not merge multiple yaml files together.)
|
61
|
+
|
62
|
+
== Simple Tour
|
63
|
+
|
64
|
+
Okay, now let's look at tours/simple.rb.
|
65
|
+
|
66
|
+
It defines a class named Simple that inherits from Tour. Tourbus won't
|
67
|
+
try to run a tour unless the file contains a Tour child class of the
|
68
|
+
same name as the file.
|
69
|
+
|
70
|
+
Inside the class, methods whose names begin with test_ will
|
71
|
+
automatically be run as part of the tour. They are not run in any
|
72
|
+
particular order.
|
73
|
+
|
74
|
+
=== test_home
|
75
|
+
|
76
|
+
Right. Let's look test_home first, because it's simpler:
|
77
|
+
|
78
|
+
def test_home
|
79
|
+
open_site_page "/"
|
80
|
+
click_link :text => /Enter Contact/
|
81
|
+
assert_page_uri_matches "/contacts"
|
82
|
+
end
|
83
|
+
|
84
|
+
+open_site_page+ is defined in Tour.rb, it opens the given path on the
|
85
|
+
host that tourbus is testing.
|
86
|
+
|
87
|
+
+click_link+ does what you'd expect. It takes a hash that identifies
|
88
|
+
the link to click. In this case I chose to identify the link with a
|
89
|
+
regexp describing its text label. +click_link+ will raise an exception
|
90
|
+
if it cannot find the link to click.
|
91
|
+
|
92
|
+
+assert_page_uri_matches+ will raise an exception unless the uri
|
93
|
+
matches the given string or regexp. If I had passed in a regexp, it
|
94
|
+
would have passed if the regexp matched. *Note:* Strings only match at
|
95
|
+
the /end/ of the uri; simple containment is not enough. Passing
|
96
|
+
"/contacts" works the same as passing %r{/contacts$}.
|
97
|
+
|
98
|
+
Clear as mud? "/contacts" would match
|
99
|
+
http://localhost:4567/users/42/contacts but not
|
100
|
+
http://localhost:4567/contacts/42.
|
101
|
+
|
102
|
+
|
103
|
+
=== test_contacts
|
104
|
+
|
105
|
+
Okay, let's actually submit a form.
|
106
|
+
|
107
|
+
def test_contacts
|
108
|
+
open_site_page "contacts"
|
109
|
+
submit_form(
|
110
|
+
:identified_by => { :action => %r{/contacts} },
|
111
|
+
:values => {
|
112
|
+
'first_name' => "Joe",
|
113
|
+
'last_name' => "Tester"
|
114
|
+
}
|
115
|
+
)
|
116
|
+
assert_page_uri_matches "/contacts"
|
117
|
+
assert_page_body_contains "Tester, Joe"
|
118
|
+
end
|
119
|
+
|
120
|
+
test_contacts starts by going directly to the contacts app. Note that
|
121
|
+
the leading "/" is optional.
|
122
|
+
|
123
|
+
+submit_form+ does what its name implies. It finds the correct form to
|
124
|
+
submit by matching the action to a regexp, then it sets the form
|
125
|
+
values and submits the form. *Note:* Like +click_link+, +submit_form+
|
126
|
+
contains some implicit assertions. It actually reads the form looking
|
127
|
+
for the named inputs and will raise an exception if any are missing.
|
128
|
+
This means you cannot use submit_form to do a blind post to a
|
129
|
+
webserver.
|
130
|
+
|
131
|
+
+assert_page_uri_matches+ we've already seen;
|
132
|
+
+assert_page_body_contains+ searches the page body for the given text
|
133
|
+
or regexp.
|
134
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
# Contact app. Example Sinatra application that you can use to test tourbus.
|
4
|
+
#
|
5
|
+
# Pretty simple applet. You go to / and enter your contact
|
6
|
+
# information. When you click submit, it shows you your name in all
|
7
|
+
# caps. Okay, "pretty simple" was an understatement. I get that. Shut up.
|
8
|
+
require 'rubygems'
|
9
|
+
require 'sinatra'
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
'<a href="/contacts">Enter Contact</a>'
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/contacts' do
|
16
|
+
<<-eos
|
17
|
+
<html>
|
18
|
+
<head>
|
19
|
+
<title>Contact App</title>
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<h1>Contact Info:</h1>
|
23
|
+
<form action="/contacts" method="POST">
|
24
|
+
<p><label for="first_name"><b>First Name:</b></label> <input name="first_name" size="30"></p>
|
25
|
+
<p><label for="last_name"><b>Last Name:</b></label> <input name="last_name" size="30"></p>
|
26
|
+
<input type="submit">
|
27
|
+
</form>
|
28
|
+
</body>
|
29
|
+
</html>
|
30
|
+
eos
|
31
|
+
end
|
32
|
+
|
33
|
+
post '/contacts' do
|
34
|
+
"<h1>#{params[:last_name]}, #{params[:first_name]}</h1>"
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Simple < Tour
|
2
|
+
def test_home
|
3
|
+
open_site_page "/"
|
4
|
+
click_link :text => /Enter Contact/
|
5
|
+
assert_page_uri_matches "/contacts"
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_contacts
|
9
|
+
open_site_page "contacts"
|
10
|
+
submit_form(
|
11
|
+
:identified_by => { :action => %r{/contacts} },
|
12
|
+
:values => {
|
13
|
+
'first_name' => "Joe",
|
14
|
+
'last_name' => "Tester"
|
15
|
+
}
|
16
|
+
)
|
17
|
+
assert_page_uri_matches "/contacts"
|
18
|
+
assert_page_body_contains "Tester, Joe"
|
19
|
+
end
|
20
|
+
end
|
data/lib/tour.rb
CHANGED
@@ -69,8 +69,10 @@ class Tour
|
|
69
69
|
puts "#{Time.now.strftime('%F %H:%M:%S')} Tour ##{@tour_id}: (#{@test}) #{message}"
|
70
70
|
end
|
71
71
|
|
72
|
-
# given "portal", opens "http://#{@host}/portal"
|
72
|
+
# given "portal", opens "http://#{@host}/portal". Leading slash is
|
73
|
+
# optional. "/portal" and "portal" are the same.
|
73
74
|
def open_site_page(path)
|
75
|
+
path = path.sub %r{^/}, ""
|
74
76
|
open_page "http://#{@host}/#{path}"
|
75
77
|
end
|
76
78
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbrady-tourbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Brady
|
@@ -58,9 +58,14 @@ extensions: []
|
|
58
58
|
extra_rdoc_files:
|
59
59
|
- README.txt
|
60
60
|
- MIT-LICENSE
|
61
|
+
- examples/contact_app/README.rdoc
|
61
62
|
files:
|
62
63
|
- bin/tourbus
|
63
64
|
- bin/tourwatch
|
65
|
+
- examples/contact_app/README.rdoc
|
66
|
+
- examples/contact_app/contact_app.rb
|
67
|
+
- examples/contact_app/tours/simple.rb
|
68
|
+
- examples/contact_app/tours/tourbus.yml
|
64
69
|
- lib/common.rb
|
65
70
|
- lib/runner.rb
|
66
71
|
- lib/tour.rb
|