nimboids-capybara 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/History.txt +289 -0
  2. data/README.rdoc +722 -0
  3. data/lib/capybara.rb +252 -0
  4. data/lib/capybara/cucumber.rb +28 -0
  5. data/lib/capybara/driver/base.rb +64 -0
  6. data/lib/capybara/driver/node.rb +74 -0
  7. data/lib/capybara/dsl.rb +168 -0
  8. data/lib/capybara/node/actions.rb +162 -0
  9. data/lib/capybara/node/base.rb +63 -0
  10. data/lib/capybara/node/document.rb +25 -0
  11. data/lib/capybara/node/element.rb +201 -0
  12. data/lib/capybara/node/finders.rb +197 -0
  13. data/lib/capybara/node/matchers.rb +417 -0
  14. data/lib/capybara/node/simple.rb +132 -0
  15. data/lib/capybara/rack_test/browser.rb +121 -0
  16. data/lib/capybara/rack_test/driver.rb +80 -0
  17. data/lib/capybara/rack_test/form.rb +80 -0
  18. data/lib/capybara/rack_test/node.rb +105 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +26 -0
  21. data/lib/capybara/rspec/features.rb +22 -0
  22. data/lib/capybara/rspec/matchers.rb +154 -0
  23. data/lib/capybara/selector.rb +89 -0
  24. data/lib/capybara/selenium/driver.rb +163 -0
  25. data/lib/capybara/selenium/node.rb +91 -0
  26. data/lib/capybara/server.rb +90 -0
  27. data/lib/capybara/session.rb +321 -0
  28. data/lib/capybara/spec/driver.rb +301 -0
  29. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  30. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  31. data/lib/capybara/spec/public/test.js +43 -0
  32. data/lib/capybara/spec/session.rb +154 -0
  33. data/lib/capybara/spec/session/all_spec.rb +78 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +73 -0
  35. data/lib/capybara/spec/session/check_spec.rb +65 -0
  36. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  37. data/lib/capybara/spec/session/click_button_spec.rb +304 -0
  38. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  39. data/lib/capybara/spec/session/click_link_spec.rb +119 -0
  40. data/lib/capybara/spec/session/current_host_spec.rb +68 -0
  41. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  42. data/lib/capybara/spec/session/fill_in_spec.rb +125 -0
  43. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  44. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  45. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  46. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  47. data/lib/capybara/spec/session/find_spec.rb +149 -0
  48. data/lib/capybara/spec/session/first_spec.rb +105 -0
  49. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  50. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  51. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  52. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  53. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  54. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  55. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  56. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  57. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  58. data/lib/capybara/spec/session/headers.rb +19 -0
  59. data/lib/capybara/spec/session/javascript.rb +289 -0
  60. data/lib/capybara/spec/session/response_code.rb +19 -0
  61. data/lib/capybara/spec/session/select_spec.rb +113 -0
  62. data/lib/capybara/spec/session/text_spec.rb +19 -0
  63. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  64. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  65. data/lib/capybara/spec/session/within_spec.rb +178 -0
  66. data/lib/capybara/spec/test_app.rb +142 -0
  67. data/lib/capybara/spec/views/buttons.erb +4 -0
  68. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  69. data/lib/capybara/spec/views/form.erb +365 -0
  70. data/lib/capybara/spec/views/frame_one.erb +8 -0
  71. data/lib/capybara/spec/views/frame_two.erb +8 -0
  72. data/lib/capybara/spec/views/header_links.erb +7 -0
  73. data/lib/capybara/spec/views/host_links.erb +12 -0
  74. data/lib/capybara/spec/views/popup_one.erb +8 -0
  75. data/lib/capybara/spec/views/popup_two.erb +8 -0
  76. data/lib/capybara/spec/views/postback.erb +13 -0
  77. data/lib/capybara/spec/views/tables.erb +122 -0
  78. data/lib/capybara/spec/views/with_html.erb +78 -0
  79. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  80. data/lib/capybara/spec/views/with_js.erb +48 -0
  81. data/lib/capybara/spec/views/with_scope.erb +36 -0
  82. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  83. data/lib/capybara/spec/views/within_frames.erb +10 -0
  84. data/lib/capybara/spec/views/within_popups.erb +25 -0
  85. data/lib/capybara/util/save_and_open_page.rb +44 -0
  86. data/lib/capybara/util/timeout.rb +27 -0
  87. data/lib/capybara/version.rb +3 -0
  88. data/spec/basic_node_spec.rb +77 -0
  89. data/spec/capybara_spec.rb +46 -0
  90. data/spec/driver/rack_test_driver_spec.rb +89 -0
  91. data/spec/driver/selenium_driver_spec.rb +50 -0
  92. data/spec/dsl_spec.rb +253 -0
  93. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  94. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  95. data/spec/rspec/features_spec.rb +45 -0
  96. data/spec/rspec/matchers_spec.rb +495 -0
  97. data/spec/rspec_spec.rb +53 -0
  98. data/spec/save_and_open_page_spec.rb +155 -0
  99. data/spec/server_spec.rb +89 -0
  100. data/spec/session/rack_test_session_spec.rb +55 -0
  101. data/spec/session/selenium_session_spec.rb +26 -0
  102. data/spec/spec_helper.rb +30 -0
  103. data/spec/string_spec.rb +77 -0
  104. data/spec/timeout_spec.rb +28 -0
  105. metadata +346 -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,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,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