capybara_minitest_spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +7 -0
  6. data/README.md +31 -0
  7. data/Rakefile +9 -0
  8. data/capybara_minitest_spec.gemspec +25 -0
  9. data/lib/capybara_minitest_spec/version.rb +3 -0
  10. data/lib/capybara_minitest_spec.rb +45 -0
  11. data/test/matchers_spec.rb +447 -0
  12. data/test/spec_helper.rb +28 -0
  13. data/test_app/driver.rb +297 -0
  14. data/test_app/fixtures/capybara.jpg +3 -0
  15. data/test_app/fixtures/test_file.txt +1 -0
  16. data/test_app/public/test.js +43 -0
  17. data/test_app/session/all_spec.rb +78 -0
  18. data/test_app/session/attach_file_spec.rb +73 -0
  19. data/test_app/session/check_spec.rb +65 -0
  20. data/test_app/session/choose_spec.rb +26 -0
  21. data/test_app/session/click_button_spec.rb +304 -0
  22. data/test_app/session/click_link_or_button_spec.rb +36 -0
  23. data/test_app/session/click_link_spec.rb +119 -0
  24. data/test_app/session/current_host_spec.rb +68 -0
  25. data/test_app/session/current_url_spec.rb +15 -0
  26. data/test_app/session/fill_in_spec.rb +125 -0
  27. data/test_app/session/find_button_spec.rb +18 -0
  28. data/test_app/session/find_by_id_spec.rb +18 -0
  29. data/test_app/session/find_field_spec.rb +26 -0
  30. data/test_app/session/find_link_spec.rb +19 -0
  31. data/test_app/session/find_spec.rb +149 -0
  32. data/test_app/session/first_spec.rb +105 -0
  33. data/test_app/session/has_button_spec.rb +32 -0
  34. data/test_app/session/has_content_spec.rb +106 -0
  35. data/test_app/session/has_css_spec.rb +243 -0
  36. data/test_app/session/has_field_spec.rb +192 -0
  37. data/test_app/session/has_link_spec.rb +37 -0
  38. data/test_app/session/has_select_spec.rb +129 -0
  39. data/test_app/session/has_selector_spec.rb +129 -0
  40. data/test_app/session/has_table_spec.rb +96 -0
  41. data/test_app/session/has_xpath_spec.rb +123 -0
  42. data/test_app/session/headers.rb +19 -0
  43. data/test_app/session/javascript.rb +289 -0
  44. data/test_app/session/response_code.rb +19 -0
  45. data/test_app/session/select_spec.rb +113 -0
  46. data/test_app/session/text_spec.rb +19 -0
  47. data/test_app/session/uncheck_spec.rb +21 -0
  48. data/test_app/session/unselect_spec.rb +61 -0
  49. data/test_app/session/within_spec.rb +178 -0
  50. data/test_app/session.rb +154 -0
  51. data/test_app/test_app.rb +142 -0
  52. data/test_app/views/buttons.erb +4 -0
  53. data/test_app/views/fieldsets.erb +29 -0
  54. data/test_app/views/form.erb +365 -0
  55. data/test_app/views/frame_one.erb +8 -0
  56. data/test_app/views/frame_two.erb +8 -0
  57. data/test_app/views/header_links.erb +7 -0
  58. data/test_app/views/host_links.erb +12 -0
  59. data/test_app/views/popup_one.erb +8 -0
  60. data/test_app/views/popup_two.erb +8 -0
  61. data/test_app/views/postback.erb +13 -0
  62. data/test_app/views/tables.erb +122 -0
  63. data/test_app/views/with_html.erb +74 -0
  64. data/test_app/views/with_html_entities.erb +1 -0
  65. data/test_app/views/with_js.erb +48 -0
  66. data/test_app/views/with_scope.erb +36 -0
  67. data/test_app/views/with_simple_html.erb +1 -0
  68. data/test_app/views/within_frames.erb +10 -0
  69. data/test_app/views/within_popups.erb +25 -0
  70. metadata +158 -0
@@ -0,0 +1,113 @@
1
+ shared_examples_for "select" do
2
+ describe "#select" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should return value of the first option" do
8
+ @session.find_field('Title').value.should == 'Mrs'
9
+ end
10
+
11
+ it "should return value of the selected option" do
12
+ @session.select("Miss", :from => 'Title')
13
+ @session.find_field('Title').value.should == 'Miss'
14
+ end
15
+
16
+ it "should return the value attribute rather than content if present" do
17
+ @session.find_field('Locale').value.should == 'en'
18
+ end
19
+
20
+ it "should select an option from a select box by id" do
21
+ @session.select("Finish", :from => 'form_locale')
22
+ @session.click_button('awesome')
23
+ extract_results(@session)['locale'].should == 'fi'
24
+ end
25
+
26
+ it "should select an option from a select box by label" do
27
+ @session.select("Finish", :from => 'Locale')
28
+ @session.click_button('awesome')
29
+ extract_results(@session)['locale'].should == 'fi'
30
+ end
31
+
32
+ it "should select an option without giving a select box" do
33
+ @session.select("Mr")
34
+ @session.click_button('awesome')
35
+ extract_results(@session)['title'].should == 'Mr'
36
+ end
37
+
38
+ it "should favour exact matches to option labels" do
39
+ @session.select("Mr", :from => 'Title')
40
+ @session.click_button('awesome')
41
+ extract_results(@session)['title'].should == 'Mr'
42
+ end
43
+
44
+ it "should escape quotes" do
45
+ @session.select("John's made-up language", :from => 'Locale')
46
+ @session.click_button('awesome')
47
+ extract_results(@session)['locale'].should == 'jo'
48
+ end
49
+
50
+ it "should obey from" do
51
+ @session.select("Miss", :from => "Other title")
52
+ @session.click_button('awesome')
53
+ results = extract_results(@session)
54
+ results['other_title'].should == "Miss"
55
+ results['title'].should_not == "Miss"
56
+ end
57
+
58
+ it "show match labels with preceding or trailing whitespace" do
59
+ @session.select("Lojban", :from => 'Locale')
60
+ @session.click_button('awesome')
61
+ extract_results(@session)['locale'].should == 'jbo'
62
+ end
63
+
64
+ context "with a locator that doesn't exist" do
65
+ it "should raise an error" do
66
+ running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
67
+ end
68
+ end
69
+
70
+ context "with an option that doesn't exist" do
71
+ it "should raise an error" do
72
+ running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::ElementNotFound)
73
+ end
74
+ end
75
+
76
+ context "with multiple select" do
77
+ it "should return an empty value" do
78
+ @session.find_field('Language').value.should == []
79
+ end
80
+
81
+ it "should return value of the selected options" do
82
+ @session.select("Ruby", :from => 'Language')
83
+ @session.select("Javascript", :from => 'Language')
84
+ @session.find_field('Language').value.should include('Ruby', 'Javascript')
85
+ end
86
+
87
+ it "should select one option" do
88
+ @session.select("Ruby", :from => 'Language')
89
+ @session.click_button('awesome')
90
+ extract_results(@session)['languages'].should == ['Ruby']
91
+ end
92
+
93
+ it "should select multiple options" do
94
+ @session.select("Ruby", :from => 'Language')
95
+ @session.select("Javascript", :from => 'Language')
96
+ @session.click_button('awesome')
97
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
98
+ end
99
+
100
+ it "should remain selected if already selected" do
101
+ @session.select("Ruby", :from => 'Language')
102
+ @session.select("Javascript", :from => 'Language')
103
+ @session.select("Ruby", :from => 'Language')
104
+ @session.click_button('awesome')
105
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
106
+ end
107
+
108
+ it "should return value attribute rather than content if present" do
109
+ @session.find_field('Underwear').value.should include('thermal')
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "text" do
2
+ describe '#text' do
3
+ before do
4
+ @session.visit('/with_simple_html')
5
+ end
6
+
7
+ it "should print the text of the page" do
8
+ @session.text.should == 'Bar'
9
+ end
10
+
11
+ context "with css as default selector" do
12
+ before { Capybara.default_selector = :css }
13
+ it "should print the text of the page" do
14
+ @session.text.should == 'Bar'
15
+ end
16
+ after { Capybara.default_selector = :xpath }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ shared_examples_for "uncheck" do
2
+ describe "#uncheck" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should uncheck a checkbox by id" do
8
+ @session.uncheck("form_pets_hamster")
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['pets'].should include('dog')
11
+ extract_results(@session)['pets'].should_not include('hamster')
12
+ end
13
+
14
+ it "should uncheck a checkbox by label" do
15
+ @session.uncheck("Hamster")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['pets'].should include('dog')
18
+ extract_results(@session)['pets'].should_not include('hamster')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ shared_examples_for "unselect" do
2
+ describe "#unselect" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ context "with multiple select" do
8
+ it "should unselect an option from a select box by id" do
9
+ @session.unselect('Commando', :from => 'form_underwear')
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
12
+ extract_results(@session)['underwear'].should_not include('Commando')
13
+ end
14
+
15
+ it "should unselect an option without a select box" do
16
+ @session.unselect('Commando')
17
+ @session.click_button('awesome')
18
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
19
+ extract_results(@session)['underwear'].should_not include('Commando')
20
+ end
21
+
22
+ it "should unselect an option from a select box by label" do
23
+ @session.unselect('Commando', :from => 'Underwear')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
26
+ extract_results(@session)['underwear'].should_not include('Commando')
27
+ end
28
+
29
+ it "should favour exact matches to option labels" do
30
+ @session.unselect("Briefs", :from => 'Underwear')
31
+ @session.click_button('awesome')
32
+ extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
33
+ extract_results(@session)['underwear'].should_not include('Briefs')
34
+ end
35
+
36
+ it "should escape quotes" do
37
+ @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
38
+ @session.click_button('awesome')
39
+ extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
40
+ end
41
+ end
42
+
43
+ context "with single select" do
44
+ it "should raise an error" do
45
+ running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
46
+ end
47
+ end
48
+
49
+ context "with a locator that doesn't exist" do
50
+ it "should raise an error" do
51
+ running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
52
+ end
53
+ end
54
+
55
+ context "with an option that doesn't exist" do
56
+ it "should raise an error" do
57
+ running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::ElementNotFound)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,178 @@
1
+ shared_examples_for "within" do
2
+ describe '#within' do
3
+ before do
4
+ @session.visit('/with_scope')
5
+ end
6
+
7
+ context "with CSS selector" do
8
+ it "should click links in the given scope" do
9
+ @session.within(:css, "ul li[contains('With Simple HTML')]") do
10
+ @session.click_link('Go')
11
+ end
12
+ @session.body.should include('Bar')
13
+ end
14
+
15
+ it "should assert content in the given scope" do
16
+ @session.within(:css, "#for_foo") do
17
+ @session.should_not have_content('First Name')
18
+ end
19
+ @session.should have_content('First Name')
20
+ end
21
+
22
+ it "should accept additional options" do
23
+ @session.within(:css, "ul li", :text => 'With Simple HTML') do
24
+ @session.click_link('Go')
25
+ end
26
+ @session.body.should include('Bar')
27
+ end
28
+ end
29
+
30
+ context "with XPath selector" do
31
+ it "should click links in the given scope" do
32
+ @session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
33
+ @session.click_link('Go')
34
+ end
35
+ @session.body.should include('Bar')
36
+ end
37
+ end
38
+
39
+ context "with the default selector" do
40
+ it "should use XPath" do
41
+ @session.within("//li[contains(., 'With Simple HTML')]") do
42
+ @session.click_link('Go')
43
+ end
44
+ @session.body.should include('Bar')
45
+ end
46
+ end
47
+
48
+ context "with Node rather than selector" do
49
+ it "should click links in the given scope" do
50
+ node_of_interest = @session.find(:css, "ul li[contains('With Simple HTML')]")
51
+
52
+ @session.within(node_of_interest) do
53
+ @session.click_link('Go')
54
+ end
55
+ @session.body.should include('Bar')
56
+ end
57
+ end
58
+
59
+ context "with the default selector set to CSS" do
60
+ before { Capybara.default_selector = :css }
61
+ it "should use CSS" do
62
+ @session.within("ul li[contains('With Simple HTML')]") do
63
+ @session.click_link('Go')
64
+ end
65
+ @session.body.should include('Bar')
66
+ end
67
+ after { Capybara.default_selector = :xpath }
68
+ end
69
+
70
+ context "with click_link" do
71
+ it "should click links in the given scope" do
72
+ @session.within("//li[contains(.,'With Simple HTML')]") do
73
+ @session.click_link('Go')
74
+ end
75
+ @session.body.should include('Bar')
76
+ end
77
+
78
+ context "with nested scopes" do
79
+ it "should respect the inner scope" do
80
+ @session.within("//div[@id='for_bar']") do
81
+ @session.within(".//li[contains(.,'Bar')]") do
82
+ @session.click_link('Go')
83
+ end
84
+ end
85
+ @session.body.should include('Another World')
86
+ end
87
+
88
+ it "should respect the outer scope" do
89
+ @session.within("//div[@id='another_foo']") do
90
+ @session.within(".//li[contains(.,'With Simple HTML')]") do
91
+ @session.click_link('Go')
92
+ end
93
+ end
94
+ @session.body.should include('Hello world')
95
+ end
96
+ end
97
+
98
+ it "should raise an error if the scope is not found on the page" do
99
+ running {
100
+ @session.within("//div[@id='doesnotexist']") do
101
+ end
102
+ }.should raise_error(Capybara::ElementNotFound)
103
+ end
104
+
105
+ it "should restore the scope when an error is raised" do
106
+ running {
107
+ @session.within("//div[@id='for_bar']") do
108
+ running {
109
+ running {
110
+ @session.within(".//div[@id='doesnotexist']") do
111
+ end
112
+ }.should raise_error(Capybara::ElementNotFound)
113
+ }.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
114
+ end
115
+ }.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
116
+ end
117
+ end
118
+
119
+ context "with forms" do
120
+ it "should fill in a field and click a button" do
121
+ @session.within("//li[contains(.,'Bar')]") do
122
+ @session.click_button('Go')
123
+ end
124
+ extract_results(@session)['first_name'].should == 'Peter'
125
+ @session.visit('/with_scope')
126
+ @session.within("//li[contains(.,'Bar')]") do
127
+ @session.fill_in('First Name', :with => 'Dagobert')
128
+ @session.click_button('Go')
129
+ end
130
+ extract_results(@session)['first_name'].should == 'Dagobert'
131
+ end
132
+ end
133
+ end
134
+
135
+ describe '#within_fieldset' do
136
+ before do
137
+ @session.visit('/fieldsets')
138
+ end
139
+
140
+ it "should restrict scope to a fieldset given by id" do
141
+ @session.within_fieldset("villain_fieldset") do
142
+ @session.fill_in("Name", :with => 'Goldfinger')
143
+ @session.click_button("Create")
144
+ end
145
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
146
+ end
147
+
148
+ it "should restrict scope to a fieldset given by legend" do
149
+ @session.within_fieldset("Villain") do
150
+ @session.fill_in("Name", :with => 'Goldfinger')
151
+ @session.click_button("Create")
152
+ end
153
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
154
+ end
155
+ end
156
+
157
+ describe '#within_table' do
158
+ before do
159
+ @session.visit('/tables')
160
+ end
161
+
162
+ it "should restrict scope to a fieldset given by id" do
163
+ @session.within_table("girl_table") do
164
+ @session.fill_in("Name", :with => 'Christmas')
165
+ @session.click_button("Create")
166
+ end
167
+ extract_results(@session)['girl_name'].should == 'Christmas'
168
+ end
169
+
170
+ it "should restrict scope to a fieldset given by legend" do
171
+ @session.within_table("Villain") do
172
+ @session.fill_in("Name", :with => 'Quantum')
173
+ @session.click_button("Create")
174
+ end
175
+ extract_results(@session)['villain_name'].should == 'Quantum'
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,154 @@
1
+ require 'capybara/spec/test_app'
2
+ require 'nokogiri'
3
+
4
+ Dir[File.dirname(__FILE__)+'/session/*'].each { |group| require group }
5
+
6
+ shared_examples_for "session" do
7
+ def extract_results(session)
8
+ YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text
9
+ end
10
+
11
+ after do
12
+ @session.reset_session!
13
+ end
14
+
15
+ describe '#visit' do
16
+ it "should fetch a response from the driver" do
17
+ @session.visit('/')
18
+ @session.body.should include('Hello world!')
19
+ @session.visit('/foo')
20
+ @session.body.should include('Another World')
21
+ end
22
+ end
23
+
24
+ describe '#body' do
25
+ it "should return the unmodified page body" do
26
+ @session.visit('/')
27
+ @session.body.should include('Hello world!')
28
+ end
29
+ end
30
+
31
+ describe '#html' do
32
+ it "should return the unmodified page body" do
33
+ # html and body should be aliased, but we can't just check for
34
+ # method(:html) == method(:body) because these shared examples get run
35
+ # against the DSL, which uses forwarding methods. So we test behavior.
36
+ @session.visit('/')
37
+ @session.body.should include('Hello world!')
38
+ end
39
+ end
40
+
41
+ describe '#source' do
42
+ it "should return the unmodified page source" do
43
+ @session.visit('/')
44
+ @session.source.should include('Hello world!')
45
+ end
46
+ end
47
+
48
+ describe '#reset_session!' do
49
+ it "removes cookies" do
50
+ @session.visit('/set_cookie')
51
+ @session.visit('/get_cookie')
52
+ @session.body.should include('test_cookie')
53
+
54
+ @session.reset_session!
55
+ @session.visit('/get_cookie')
56
+ @session.body.should_not include('test_cookie')
57
+ end
58
+
59
+ it "resets current host" do
60
+ @session.visit('http://capybara-testapp.heroku.com')
61
+ @session.current_host.should == 'http://capybara-testapp.heroku.com'
62
+
63
+ @session.reset_session!
64
+ @session.current_host.should be_nil
65
+ end
66
+
67
+ it "resets current path" do
68
+ @session.visit('/with_html')
69
+ @session.current_path.should == '/with_html'
70
+
71
+ @session.reset_session!
72
+ @session.current_path.should be_nil
73
+ end
74
+
75
+ it "resets page body" do
76
+ @session.visit('/with_html')
77
+ @session.body.should include('This is a test')
78
+ @session.find('.//h1').text.should include('This is a test')
79
+
80
+ @session.reset_session!
81
+ @session.body.should_not include('This is a test')
82
+ @session.should have_no_selector('.//h1')
83
+ end
84
+ end
85
+
86
+ it_should_behave_like "all"
87
+ it_should_behave_like "first"
88
+ it_should_behave_like "attach_file"
89
+ it_should_behave_like "check"
90
+ it_should_behave_like "choose"
91
+ it_should_behave_like "click_link_or_button"
92
+ it_should_behave_like "click_button"
93
+ it_should_behave_like "click_link"
94
+ it_should_behave_like "fill_in"
95
+ it_should_behave_like "find_button"
96
+ it_should_behave_like "find_field"
97
+ it_should_behave_like "find_link"
98
+ it_should_behave_like "find_by_id"
99
+ it_should_behave_like "find"
100
+ it_should_behave_like "has_content"
101
+ it_should_behave_like "has_css"
102
+ it_should_behave_like "has_css"
103
+ it_should_behave_like "has_selector"
104
+ it_should_behave_like "has_xpath"
105
+ it_should_behave_like "has_link"
106
+ it_should_behave_like "has_button"
107
+ it_should_behave_like "has_field"
108
+ it_should_behave_like "has_select"
109
+ it_should_behave_like "has_table"
110
+ it_should_behave_like "select"
111
+ it_should_behave_like "text"
112
+ it_should_behave_like "uncheck"
113
+ it_should_behave_like "unselect"
114
+ it_should_behave_like "within"
115
+ it_should_behave_like "current_url"
116
+ it_should_behave_like "current_host"
117
+
118
+ it "should encode complex field names, like array[][value]" do
119
+ @session.visit('/form')
120
+ @session.fill_in('address1_city', :with =>'Paris')
121
+ @session.fill_in('address1_street', :with =>'CDG')
122
+ @session.fill_in('address1_street', :with =>'CDG')
123
+ @session.select("France", :from => 'address1_country')
124
+
125
+ @session.fill_in('address2_city', :with => 'Mikolaiv')
126
+ @session.fill_in('address2_street', :with => 'PGS')
127
+ @session.select("Ukraine", :from => 'address2_country')
128
+
129
+ @session.click_button "awesome"
130
+
131
+ addresses=extract_results(@session)["addresses"]
132
+ addresses.should have(2).addresses
133
+
134
+ addresses[0]["street"].should == 'CDG'
135
+ addresses[0]["city"].should == 'Paris'
136
+ addresses[0]["country"].should == 'France'
137
+
138
+ addresses[1]["street"].should == 'PGS'
139
+ addresses[1]["city"].should == 'Mikolaiv'
140
+ addresses[1]["country"].should == 'Ukraine'
141
+ end
142
+
143
+ end
144
+
145
+
146
+ describe Capybara::Session do
147
+ context 'with non-existant driver' do
148
+ it "should raise an error" do
149
+ running {
150
+ Capybara::Session.new(:quox, TestApp).driver
151
+ }.should raise_error(Capybara::DriverNotFoundError)
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,142 @@
1
+ require 'sinatra/base'
2
+ require 'rack'
3
+ require 'yaml'
4
+
5
+ class TestApp < Sinatra::Base
6
+ set :root, File.dirname(__FILE__)
7
+ set :static, true
8
+
9
+ get '/' do
10
+ 'Hello world! <a href="with_html">Relative</a>'
11
+ end
12
+
13
+ get '/foo' do
14
+ 'Another World'
15
+ end
16
+
17
+ get '/redirect' do
18
+ redirect '/redirect_again'
19
+ end
20
+
21
+ get '/redirect_again' do
22
+ redirect '/landed'
23
+ end
24
+
25
+ get '/host' do
26
+ "Current host is #{request.scheme}://#{request.host}"
27
+ end
28
+
29
+ get '/redirect/:times/times' do
30
+ times = params[:times].to_i
31
+ if times.zero?
32
+ "redirection complete"
33
+ else
34
+ redirect "/redirect/#{times - 1}/times"
35
+ end
36
+ end
37
+
38
+ get '/landed' do
39
+ "You landed"
40
+ end
41
+
42
+ get '/with-quotes' do
43
+ %q{"No," he said, "you can't do that."}
44
+ end
45
+
46
+ get '/form/get' do
47
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
48
+ end
49
+
50
+ post '/relative' do
51
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
52
+ end
53
+
54
+ get '/favicon.ico' do
55
+ nil
56
+ end
57
+
58
+ post '/redirect' do
59
+ redirect '/redirect_again'
60
+ end
61
+
62
+ delete "/delete" do
63
+ "The requested object was deleted"
64
+ end
65
+
66
+ get "/delete" do
67
+ "Not deleted"
68
+ end
69
+
70
+ get '/redirect_back' do
71
+ redirect back
72
+ end
73
+
74
+ get '/redirect_secure' do
75
+ redirect "https://#{request.host}/host"
76
+ end
77
+
78
+ get '/slow_response' do
79
+ sleep 2
80
+ 'Finally!'
81
+ end
82
+
83
+ get '/set_cookie' do
84
+ cookie_value = 'test_cookie'
85
+ response.set_cookie('capybara', cookie_value)
86
+ "Cookie set to #{cookie_value}"
87
+ end
88
+
89
+ get '/get_cookie' do
90
+ request.cookies['capybara']
91
+ end
92
+
93
+ get '/get_header' do
94
+ env['HTTP_FOO']
95
+ end
96
+
97
+ get '/get_header_via_redirect' do
98
+ redirect '/get_header'
99
+ end
100
+
101
+ get '/:view' do |view|
102
+ erb view.to_sym
103
+ end
104
+
105
+ post '/form' do
106
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
107
+ end
108
+
109
+ post '/upload_empty' do
110
+ if params[:form][:file].nil?
111
+ 'Successfully ignored empty file field.'
112
+ else
113
+ 'Something went wrong.'
114
+ end
115
+ end
116
+
117
+ post '/upload' do
118
+ begin
119
+ buffer = []
120
+ buffer << "Content-type: #{params[:form][:document][:type]}"
121
+ buffer << "File content: #{params[:form][:document][:tempfile].read}"
122
+ buffer.join(' | ')
123
+ rescue
124
+ 'No file uploaded'
125
+ end
126
+ end
127
+
128
+ post '/upload_multiple' do
129
+ begin
130
+ buffer = []
131
+ buffer << "Content-type: #{params[:form][:multiple_documents][0][:type]}"
132
+ buffer << "File content: #{params[:form][:multiple_documents][0][:tempfile].read}"
133
+ buffer.join(' | ')
134
+ rescue
135
+ 'No files uploaded'
136
+ end
137
+ end
138
+ end
139
+
140
+ if __FILE__ == $0
141
+ Rack::Handler::WEBrick.run TestApp, :Port => 8070
142
+ end
@@ -0,0 +1,4 @@
1
+ <h1>Buttons</h1>
2
+ <button>Click me!</button>
3
+ <button id="click_me_123">Click me by id!</button>
4
+ <button value="click_me">Click me by value!</button>