bbc-capybara 1.1.2

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.
Files changed (107) hide show
  1. data/History.txt +325 -0
  2. data/License.txt +22 -0
  3. data/README.md +815 -0
  4. data/lib/capybara.rb +368 -0
  5. data/lib/capybara/cucumber.rb +25 -0
  6. data/lib/capybara/driver/base.rb +64 -0
  7. data/lib/capybara/driver/node.rb +74 -0
  8. data/lib/capybara/dsl.rb +50 -0
  9. data/lib/capybara/node/actions.rb +146 -0
  10. data/lib/capybara/node/base.rb +63 -0
  11. data/lib/capybara/node/document.rb +25 -0
  12. data/lib/capybara/node/element.rb +201 -0
  13. data/lib/capybara/node/finders.rb +154 -0
  14. data/lib/capybara/node/matchers.rb +442 -0
  15. data/lib/capybara/node/simple.rb +132 -0
  16. data/lib/capybara/query.rb +63 -0
  17. data/lib/capybara/rack_test/browser.rb +126 -0
  18. data/lib/capybara/rack_test/driver.rb +80 -0
  19. data/lib/capybara/rack_test/form.rb +80 -0
  20. data/lib/capybara/rack_test/node.rb +121 -0
  21. data/lib/capybara/rails.rb +17 -0
  22. data/lib/capybara/rspec.rb +26 -0
  23. data/lib/capybara/rspec/features.rb +22 -0
  24. data/lib/capybara/rspec/matchers.rb +152 -0
  25. data/lib/capybara/selector.rb +156 -0
  26. data/lib/capybara/selenium/driver.rb +169 -0
  27. data/lib/capybara/selenium/node.rb +91 -0
  28. data/lib/capybara/server.rb +87 -0
  29. data/lib/capybara/session.rb +322 -0
  30. data/lib/capybara/spec/driver.rb +329 -0
  31. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  32. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  33. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  34. data/lib/capybara/spec/public/jquery.js +9046 -0
  35. data/lib/capybara/spec/public/test.js +43 -0
  36. data/lib/capybara/spec/session.rb +148 -0
  37. data/lib/capybara/spec/session/all_spec.rb +78 -0
  38. data/lib/capybara/spec/session/attach_file_spec.rb +76 -0
  39. data/lib/capybara/spec/session/check_spec.rb +68 -0
  40. data/lib/capybara/spec/session/choose_spec.rb +29 -0
  41. data/lib/capybara/spec/session/click_button_spec.rb +305 -0
  42. data/lib/capybara/spec/session/click_link_or_button_spec.rb +37 -0
  43. data/lib/capybara/spec/session/click_link_spec.rb +120 -0
  44. data/lib/capybara/spec/session/current_url_spec.rb +83 -0
  45. data/lib/capybara/spec/session/fill_in_spec.rb +127 -0
  46. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  47. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  48. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  49. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  50. data/lib/capybara/spec/session/find_spec.rb +168 -0
  51. data/lib/capybara/spec/session/first_spec.rb +105 -0
  52. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  53. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  54. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  55. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  56. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  57. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  58. data/lib/capybara/spec/session/has_table_spec.rb +34 -0
  59. data/lib/capybara/spec/session/has_text_spec.rb +138 -0
  60. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  61. data/lib/capybara/spec/session/headers.rb +19 -0
  62. data/lib/capybara/spec/session/javascript.rb +312 -0
  63. data/lib/capybara/spec/session/response_code.rb +19 -0
  64. data/lib/capybara/spec/session/select_spec.rb +119 -0
  65. data/lib/capybara/spec/session/text_spec.rb +24 -0
  66. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  67. data/lib/capybara/spec/session/unselect_spec.rb +67 -0
  68. data/lib/capybara/spec/session/within_spec.rb +178 -0
  69. data/lib/capybara/spec/test_app.rb +156 -0
  70. data/lib/capybara/spec/views/buttons.erb +4 -0
  71. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  72. data/lib/capybara/spec/views/form.erb +366 -0
  73. data/lib/capybara/spec/views/frame_one.erb +8 -0
  74. data/lib/capybara/spec/views/frame_two.erb +8 -0
  75. data/lib/capybara/spec/views/header_links.erb +7 -0
  76. data/lib/capybara/spec/views/host_links.erb +12 -0
  77. data/lib/capybara/spec/views/popup_one.erb +8 -0
  78. data/lib/capybara/spec/views/popup_two.erb +8 -0
  79. data/lib/capybara/spec/views/postback.erb +13 -0
  80. data/lib/capybara/spec/views/tables.erb +62 -0
  81. data/lib/capybara/spec/views/with_html.erb +75 -0
  82. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  83. data/lib/capybara/spec/views/with_js.erb +53 -0
  84. data/lib/capybara/spec/views/with_scope.erb +36 -0
  85. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  86. data/lib/capybara/spec/views/within_frames.erb +10 -0
  87. data/lib/capybara/spec/views/within_popups.erb +25 -0
  88. data/lib/capybara/util/save_and_open_page.rb +45 -0
  89. data/lib/capybara/util/timeout.rb +27 -0
  90. data/lib/capybara/version.rb +3 -0
  91. data/spec/basic_node_spec.rb +89 -0
  92. data/spec/capybara_spec.rb +46 -0
  93. data/spec/driver/rack_test_driver_spec.rb +90 -0
  94. data/spec/driver/selenium_driver_spec.rb +55 -0
  95. data/spec/dsl_spec.rb +255 -0
  96. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  97. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  98. data/spec/rspec/features_spec.rb +43 -0
  99. data/spec/rspec/matchers_spec.rb +564 -0
  100. data/spec/rspec_spec.rb +51 -0
  101. data/spec/save_and_open_page_spec.rb +155 -0
  102. data/spec/server_spec.rb +74 -0
  103. data/spec/session/rack_test_session_spec.rb +61 -0
  104. data/spec/session/selenium_session_spec.rb +26 -0
  105. data/spec/spec_helper.rb +31 -0
  106. data/spec/timeout_spec.rb +28 -0
  107. metadata +297 -0
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with status code support" do
2
+ describe '#status_code' do
3
+ it "should return response codes" do
4
+ @session.visit('/with_simple_html')
5
+ @session.status_code.should == 200
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without status code support" do
11
+ describe "#status_code" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.status_code
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,119 @@
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
+ msg = "no select box with id, name, or label 'does not exist' found"
67
+ running do
68
+ @session.select('foo', :from => 'does not exist')
69
+ end.should raise_error(Capybara::ElementNotFound, msg)
70
+ end
71
+ end
72
+
73
+ context "with an option that doesn't exist" do
74
+ it "should raise an error" do
75
+ msg = "no option with text 'Does not Exist' in the select box"
76
+ running do
77
+ @session.select('Does not Exist', :from => 'form_locale')
78
+ end.should raise_error(Capybara::ElementNotFound, msg)
79
+ end
80
+ end
81
+
82
+ context "with multiple select" do
83
+ it "should return an empty value" do
84
+ @session.find_field('Language').value.should == []
85
+ end
86
+
87
+ it "should return value of the selected options" do
88
+ @session.select("Ruby", :from => 'Language')
89
+ @session.select("Javascript", :from => 'Language')
90
+ @session.find_field('Language').value.should include('Ruby', 'Javascript')
91
+ end
92
+
93
+ it "should select one option" do
94
+ @session.select("Ruby", :from => 'Language')
95
+ @session.click_button('awesome')
96
+ extract_results(@session)['languages'].should == ['Ruby']
97
+ end
98
+
99
+ it "should select multiple options" do
100
+ @session.select("Ruby", :from => 'Language')
101
+ @session.select("Javascript", :from => 'Language')
102
+ @session.click_button('awesome')
103
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
104
+ end
105
+
106
+ it "should remain selected if already selected" do
107
+ @session.select("Ruby", :from => 'Language')
108
+ @session.select("Javascript", :from => 'Language')
109
+ @session.select("Ruby", :from => 'Language')
110
+ @session.click_button('awesome')
111
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
112
+ end
113
+
114
+ it "should return value attribute rather than content if present" do
115
+ @session.find_field('Underwear').value.should include('thermal')
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,24 @@
1
+ shared_examples_for "text" do
2
+ describe '#text' do
3
+ it "should print the text of the page" do
4
+ @session.visit('/with_simple_html')
5
+ @session.text.should == 'Bar'
6
+ end
7
+
8
+ context "with css as default selector" do
9
+ before { Capybara.default_selector = :css }
10
+ it "should print the text of the page" do
11
+ @session.visit('/with_simple_html')
12
+ @session.text.should == 'Bar'
13
+ end
14
+ after { Capybara.default_selector = :xpath }
15
+ end
16
+
17
+ it "should strip whitespace" do
18
+ @session.visit('/with_html')
19
+ n = @session.find(:css, '#second')
20
+ @session.find(:css, '#second').text.should =~ \
21
+ /\ADuis aute .* text with whitespace .* est laborum\.\z/
22
+ end
23
+ end
24
+ 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,67 @@
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
+ msg = "no select box with id, name, or label 'does not exist' found"
52
+ running do
53
+ @session.unselect('foo', :from => 'does not exist')
54
+ end.should raise_error(Capybara::ElementNotFound, msg)
55
+ end
56
+ end
57
+
58
+ context "with an option that doesn't exist" do
59
+ it "should raise an error" do
60
+ msg = "no option with text 'Does not Exist' in the select box"
61
+ running do
62
+ @session.unselect('Does not Exist', :from => 'form_underwear')
63
+ end.should raise_error(Capybara::ElementNotFound, msg)
64
+ end
65
+ end
66
+ end
67
+ 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 do
100
+ @session.within("//div[@id='doesnotexist']") do
101
+ end
102
+ end.should raise_error(Capybara::ElementNotFound)
103
+ end
104
+
105
+ it "should restore the scope when an error is raised" do
106
+ running do
107
+ @session.within("//div[@id='for_bar']") do
108
+ running do
109
+ running do
110
+ @session.within(".//div[@id='doesnotexist']") do
111
+ end
112
+ end.should raise_error(Capybara::ElementNotFound)
113
+ end.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
114
+ end
115
+ end.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,156 @@
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
+ # Also check lib/capybara/spec/views/*.erb for pages not listed here
10
+
11
+ get '/' do
12
+ 'Hello world! <a href="with_html">Relative</a>'
13
+ end
14
+
15
+ get '/foo' do
16
+ 'Another World'
17
+ end
18
+
19
+ get '/redirect' do
20
+ redirect '/redirect_again'
21
+ end
22
+
23
+ get '/redirect_again' do
24
+ redirect '/landed'
25
+ end
26
+
27
+ get '/referer_base' do
28
+ '<a href="/get_referer">direct link</a>; <a href="/redirect_to_get_referer">link via redirect</a>'
29
+ end
30
+
31
+ get '/redirect_to_get_referer' do
32
+ redirect '/get_referer'
33
+ end
34
+
35
+ get '/get_referer' do
36
+ request.referer.nil? ? "No referer" : "Got referer: #{request.referer}"
37
+ end
38
+
39
+ get '/host' do
40
+ "Current host is #{request.scheme}://#{request.host}:#{request.port}"
41
+ end
42
+
43
+ get '/redirect/:times/times' do
44
+ times = params[:times].to_i
45
+ if times.zero?
46
+ "redirection complete"
47
+ else
48
+ redirect "/redirect/#{times - 1}/times"
49
+ end
50
+ end
51
+
52
+ get '/landed' do
53
+ "You landed"
54
+ end
55
+
56
+ get '/with-quotes' do
57
+ %q{"No," he said, "you can't do that."}
58
+ end
59
+
60
+ get '/form/get' do
61
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
62
+ end
63
+
64
+ post '/relative' do
65
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
66
+ end
67
+
68
+ get '/favicon.ico' do
69
+ nil
70
+ end
71
+
72
+ post '/redirect' do
73
+ redirect '/redirect_again'
74
+ end
75
+
76
+ delete "/delete" do
77
+ "The requested object was deleted"
78
+ end
79
+
80
+ get "/delete" do
81
+ "Not deleted"
82
+ end
83
+
84
+ get '/redirect_back' do
85
+ redirect back
86
+ end
87
+
88
+ get '/redirect_secure' do
89
+ redirect "https://#{request.host}:#{request.port}/host"
90
+ end
91
+
92
+ get '/slow_response' do
93
+ sleep 2
94
+ 'Finally!'
95
+ end
96
+
97
+ get '/set_cookie' do
98
+ cookie_value = 'test_cookie'
99
+ response.set_cookie('capybara', cookie_value)
100
+ "Cookie set to #{cookie_value}"
101
+ end
102
+
103
+ get '/get_cookie' do
104
+ request.cookies['capybara']
105
+ end
106
+
107
+ get '/get_header' do
108
+ env['HTTP_FOO']
109
+ end
110
+
111
+ get '/get_header_via_redirect' do
112
+ redirect '/get_header'
113
+ end
114
+
115
+ get '/:view' do |view|
116
+ erb view.to_sym
117
+ end
118
+
119
+ post '/form' do
120
+ '<pre id="results">' + params[:form].to_yaml + '</pre>'
121
+ end
122
+
123
+ post '/upload_empty' do
124
+ if params[:form][:file].nil?
125
+ 'Successfully ignored empty file field.'
126
+ else
127
+ 'Something went wrong.'
128
+ end
129
+ end
130
+
131
+ post '/upload' do
132
+ begin
133
+ buffer = []
134
+ buffer << "Content-type: #{params[:form][:document][:type]}"
135
+ buffer << "File content: #{params[:form][:document][:tempfile].read}"
136
+ buffer.join(' | ')
137
+ rescue
138
+ 'No file uploaded'
139
+ end
140
+ end
141
+
142
+ post '/upload_multiple' do
143
+ begin
144
+ buffer = []
145
+ buffer << "Content-type: #{params[:form][:multiple_documents][0][:type]}"
146
+ buffer << "File content: #{params[:form][:multiple_documents][0][:tempfile].read}"
147
+ buffer.join(' | ')
148
+ rescue
149
+ 'No files uploaded'
150
+ end
151
+ end
152
+ end
153
+
154
+ if __FILE__ == $0
155
+ Rack::Handler::WEBrick.run TestApp, :Port => 8070
156
+ end