webrat 0.5.3 → 0.6.0

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 (87) hide show
  1. data/.gitignore +4 -1
  2. data/Gemfile +19 -0
  3. data/History.txt +29 -0
  4. data/Rakefile +27 -63
  5. data/Thorfile +117 -0
  6. data/lib/webrat.rb +11 -3
  7. data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +0 -0
  8. data/lib/webrat/adapters/merb.rb +11 -0
  9. data/lib/webrat/{rack.rb → adapters/rack.rb} +0 -0
  10. data/lib/webrat/{rails.rb → adapters/rails.rb} +2 -23
  11. data/lib/webrat/{sinatra.rb → adapters/sinatra.rb} +0 -2
  12. data/lib/webrat/core.rb +0 -1
  13. data/lib/webrat/core/configuration.rb +6 -16
  14. data/lib/webrat/core/elements/area.rb +2 -2
  15. data/lib/webrat/core/elements/element.rb +3 -3
  16. data/lib/webrat/core/elements/field.rb +106 -30
  17. data/lib/webrat/core/elements/form.rb +4 -4
  18. data/lib/webrat/core/elements/label.rb +4 -4
  19. data/lib/webrat/core/elements/link.rb +6 -6
  20. data/lib/webrat/core/elements/select_option.rb +15 -2
  21. data/lib/webrat/core/locators.rb +1 -1
  22. data/lib/webrat/core/locators/area_locator.rb +3 -3
  23. data/lib/webrat/core/locators/button_locator.rb +6 -6
  24. data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
  25. data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
  26. data/lib/webrat/core/locators/field_named_locator.rb +3 -3
  27. data/lib/webrat/core/locators/form_locator.rb +1 -1
  28. data/lib/webrat/core/locators/label_locator.rb +2 -2
  29. data/lib/webrat/core/locators/link_locator.rb +7 -7
  30. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  31. data/lib/webrat/core/logging.rb +4 -5
  32. data/lib/webrat/core/matchers/have_content.rb +2 -7
  33. data/lib/webrat/core/matchers/have_xpath.rb +3 -28
  34. data/lib/webrat/core/methods.rb +1 -0
  35. data/lib/webrat/core/scope.rb +17 -2
  36. data/lib/webrat/core/session.rb +2 -1
  37. data/lib/webrat/core/xml.rb +41 -84
  38. data/lib/webrat/integrations/merb.rb +10 -0
  39. data/lib/webrat/integrations/rails.rb +25 -0
  40. data/lib/webrat/integrations/rspec-rails.rb +11 -0
  41. data/lib/webrat/integrations/selenium.rb +11 -0
  42. data/lib/webrat/rspec-rails.rb +2 -10
  43. data/lib/webrat/selenium.rb +0 -10
  44. data/lib/webrat/selenium/application_servers.rb +1 -1
  45. data/lib/webrat/selenium/application_servers/external.rb +1 -1
  46. data/lib/webrat/selenium/location_strategy_javascript/label.js +29 -3
  47. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  48. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  49. data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
  50. data/lib/webrat/selenium/selenium_session.rb +21 -2
  51. data/lib/webrat/selenium/silence_stream.rb +1 -1
  52. data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
  53. data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
  54. data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
  55. data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
  56. data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
  57. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  58. data/spec/integration/rails/config/environment.rb +1 -1
  59. data/spec/integration/rails/config/routes.rb +1 -0
  60. data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
  61. data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
  62. data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
  63. data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
  64. data/spec/integration/rails/test/test_helper.rb +1 -0
  65. data/spec/private/core/configuration_spec.rb +2 -31
  66. data/spec/private/core/field_spec.rb +14 -16
  67. data/spec/private/mechanize/mechanize_adapter_spec.rb +0 -2
  68. data/spec/private/nokogiri_spec.rb +2 -2
  69. data/spec/private/rails/rails_adapter_spec.rb +0 -27
  70. data/spec/public/basic_auth_spec.rb +13 -2
  71. data/spec/public/click_button_spec.rb +10 -12
  72. data/spec/public/click_link_spec.rb +21 -0
  73. data/spec/public/fill_in_spec.rb +15 -0
  74. data/spec/public/matchers/have_selector_spec.rb +4 -0
  75. data/spec/public/select_spec.rb +232 -26
  76. data/spec/spec_helper.rb +2 -0
  77. data/webrat.gemspec +305 -313
  78. metadata +21 -25
  79. data/VERSION +0 -1
  80. data/lib/webrat/core/xml/hpricot.rb +0 -19
  81. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  82. data/lib/webrat/core/xml/rexml.rb +0 -24
  83. data/lib/webrat/merb_adapter.rb +0 -82
  84. data/lib/webrat/merb_multipart_support.rb +0 -27
  85. data/spec/private/core/logging_spec.rb +0 -10
  86. data/spec/private/merb/attaches_file_spec.rb +0 -93
  87. data/spec/private/merb/merb_adapter_spec.rb +0 -61
@@ -12,6 +12,7 @@ require "webrat"
12
12
 
13
13
  Webrat.configure do |config|
14
14
  config.mode = ENV['WEBRAT_INTEGRATION_MODE'].to_sym
15
+ config.selenium_browser_key = '*safari'
15
16
  end
16
17
 
17
18
  ActionController::Base.class_eval do
@@ -1,28 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  describe Webrat::Configuration do
4
-
5
- Spec::Matchers.define :parse_with_nokogiri do
6
- match do |config|
7
- config.parse_with_nokogiri?
8
- end
9
- end
10
-
4
+
11
5
  Spec::Matchers.define :open_error_files do
12
6
  match do |config|
13
7
  config.open_error_files?
14
8
  end
15
9
  end
16
-
10
+
17
11
  it "should have a mode" do
18
12
  Webrat.configuration.should respond_to(:mode)
19
13
  end
20
14
 
21
- it "should use Nokogiri as the parser by default" do
22
- config = Webrat::Configuration.new
23
- config.should parse_with_nokogiri
24
- end
25
-
26
15
  it "should open error files by default" do
27
16
  config = Webrat::Configuration.new
28
17
  config.should open_error_files
@@ -56,24 +45,6 @@ describe Webrat::Configuration do
56
45
  config.selenium_server_port.should == 1234
57
46
  end
58
47
 
59
- [:rails,
60
- :selenium,
61
- :rack,
62
- :sinatra,
63
- :mechanize].each do |mode|
64
- it "should require correct lib when in #{mode} mode" do
65
- config = Webrat::Configuration.new
66
- config.should_receive(:require).with("webrat/#{mode}")
67
- config.mode = mode
68
- end
69
- end
70
-
71
- it "should require merb_adapter when in merb mode" do
72
- config = Webrat::Configuration.new
73
- config.should_receive(:require).with("webrat/merb_adapter")
74
- config.mode = :merb
75
- end
76
-
77
48
  describe "Selenium" do
78
49
  before :each do
79
50
  @config = Webrat::Configuration.new
@@ -2,18 +2,16 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  module Webrat
4
4
  describe Field do
5
- unless RUBY_PLATFORM =~ /java/
6
- it "should have nice inspect output" do
7
- html = <<-HTML
8
- <html>
9
- <input type='checkbox' checked='checked' />
10
- </html>
11
- HTML
5
+ it "should have nice inspect output" do
6
+ html = <<-HTML
7
+ <html>
8
+ <input type='checkbox' checked='checked' />
9
+ </html>
10
+ HTML
12
11
 
13
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
14
- checkbox = CheckboxField.new(nil, element)
15
- checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
16
- end
12
+ element = Webrat::XML.document(html).css("input").first
13
+ checkbox = CheckboxField.new(nil, element)
14
+ checkbox.inspect.should =~ /^#<Webrat::CheckboxField @element=/
17
15
  end
18
16
  end
19
17
 
@@ -25,7 +23,7 @@ module Webrat
25
23
  </html>
26
24
  HTML
27
25
 
28
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
26
+ element = Webrat::XML.document(html).css("input").first
29
27
  checkbox = CheckboxField.new(nil, element)
30
28
  checkbox.should be_checked
31
29
  end
@@ -37,7 +35,7 @@ module Webrat
37
35
  </html>
38
36
  HTML
39
37
 
40
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
38
+ element = Webrat::XML.document(html).css("input").first
41
39
  checkbox = CheckboxField.new(nil, element)
42
40
  checkbox.should_not be_checked
43
41
  end
@@ -51,7 +49,7 @@ module Webrat
51
49
  </html>
52
50
  HTML
53
51
 
54
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
52
+ element = Webrat::XML.document(html).css("input").first
55
53
  radio_button = RadioField.new(nil, element)
56
54
  radio_button.should be_checked
57
55
  end
@@ -61,7 +59,7 @@ module Webrat
61
59
  <html><input type='radio' /></html>
62
60
  HTML
63
61
 
64
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
62
+ element = Webrat::XML.document(html).css("input").first
65
63
  radio_button = RadioField.new(nil, element)
66
64
  radio_button.should_not be_checked
67
65
  end
@@ -77,7 +75,7 @@ module Webrat
77
75
  </html>
78
76
  HTML
79
77
 
80
- element = Webrat::XML.css_search(Webrat::XML.document(html), 'input').first
78
+ element = Webrat::XML.document(html).css('input').first
81
79
  text_field = TextField.new(nil, element)
82
80
  text_field.to_param.should == { 'email' => 'user@example.com' }
83
81
  end
@@ -1,7 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- require "webrat/mechanize"
4
-
5
3
  describe Webrat::MechanizeAdapter do
6
4
  before :each do
7
5
  Webrat.configuration.mode = :mechanize
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
3
+ # if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
4
4
  describe "Nokogiri Extension" do
5
5
  include Webrat::Matchers
6
6
 
@@ -74,4 +74,4 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
74
74
  end
75
75
  end
76
76
  end
77
- end
77
+ # end
@@ -1,8 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- require "action_controller"
4
- require "webrat/rails"
5
-
6
3
  describe Webrat::RailsAdapter do
7
4
  before :each do
8
5
  Webrat.configuration.mode = :rails
@@ -86,28 +83,4 @@ describe Webrat::RailsAdapter do
86
83
  it "should provide a doc_root" do
87
84
  Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
88
85
  end
89
-
90
- it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
91
- pending "Move this to spec/public/within_spec.rb"
92
-
93
- body = <<-HTML
94
- <a href="/page1">Edit</a>
95
- <div id="new_object">
96
- <a href="/page2">Edit</a>
97
- </div>
98
- HTML
99
-
100
- response = mock("response", :body => body, :headers => {}, :code => 200)
101
- @integration_session.stub!(:response => response)
102
- @integration_session.should_receive(:get).with("/page2", {}, nil)
103
-
104
- rails_session = Webrat::RailsAdapter.new(@integration_session)
105
-
106
- object = Object.new
107
- object.stub!(:id => nil)
108
-
109
- rails_session.within(object) do
110
- rails_session.click_link 'Edit'
111
- end
112
- end
113
86
  end
@@ -6,7 +6,7 @@ describe "Basic Auth HTTP headers" do
6
6
  end
7
7
 
8
8
  it "should be present in visit" do
9
- webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
9
+ webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="})
10
10
  visit("/")
11
11
  end
12
12
 
@@ -18,7 +18,18 @@ describe "Basic Auth HTTP headers" do
18
18
  </form>
19
19
  </html>
20
20
  HTML
21
- webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
21
+ webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="})
22
22
  click_button
23
23
  end
24
+
25
+ context "with long username and password combination" do
26
+ before do
27
+ basic_auth('user', 'secret1234567890123456789012345678901234567890123456789012345678901234567890')
28
+ end
29
+
30
+ it "should be present, without new lines, in visit" do
31
+ webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkw"})
32
+ visit("/")
33
+ end
34
+ end
24
35
  end
@@ -331,18 +331,16 @@ describe "click_button" do
331
331
  end
332
332
 
333
333
  it "should properly handle HTML entities in textarea default values" do
334
- pending "needs bug fix" do
335
- with_html <<-HTML
336
- <html>
337
- <form method="post" action="/posts">
338
- <textarea name="post[body]">Peanut butter &amp; jelly</textarea>
339
- <input type="submit" />
340
- </form>
341
- </html>
342
- HTML
343
- webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
344
- click_button
345
- end
334
+ with_html <<-HTML
335
+ <html>
336
+ <form method="post" action="/posts">
337
+ <textarea name="post[body]">Peanut butter &amp; jelly</textarea>
338
+ <input type="submit" />
339
+ </form>
340
+ </html>
341
+ HTML
342
+ webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
343
+ click_button
346
344
  end
347
345
 
348
346
  it "should send default selected option value from select" do
@@ -144,6 +144,27 @@ describe "click_link" do
144
144
  click_link "Posts"
145
145
  end
146
146
 
147
+ it "should click rails 2.3.4 javascript links with authenticity tokens" do
148
+ with_html <<-HTML
149
+ <html>
150
+ <a href="/posts" onclick="var f = document.createElement('form');
151
+ f.style.display = 'none';
152
+ this.parentNode.appendChild(f);
153
+ f.method = 'POST';
154
+ f.action = this.href;
155
+ var s = document.createElement('input');
156
+ s.setAttribute('type', 'hidden');
157
+ s.setAttribute('name', 'authenticity_token');
158
+ s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a');
159
+ f.appendChild(s);
160
+ f.submit();
161
+ return false;">Posts</a>
162
+ </html>
163
+ HTML
164
+ webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a")
165
+ click_link "Posts"
166
+ end
167
+
147
168
  it "should click rails javascript delete links" do
148
169
  with_html <<-HTML
149
170
  <html>
@@ -16,6 +16,21 @@ describe "fill_in" do
16
16
  click_button
17
17
  end
18
18
 
19
+ it "should support multiline values" do
20
+ with_html <<-HTML
21
+ <html>
22
+ <form method="post" action="/login">
23
+ <label for="user_text">User Text</label>
24
+ <textarea id="user_text" name="user[text]"></textarea>
25
+ <input type="submit" />
26
+ </form>
27
+ </html>
28
+ HTML
29
+ webrat_session.should_receive(:post).with("/login", "user" => {"text" => "One\nTwo"})
30
+ fill_in "User Text", :with => "One\nTwo"
31
+ click_button
32
+ end
33
+
19
34
  it "should work with password fields" do
20
35
  with_html <<-HTML
21
36
  <html>
@@ -61,6 +61,10 @@ describe "have_selector" do
61
61
  @body.should have_selector("li", :count => 4)
62
62
  }.should raise_error(Spec::Expectations::ExpectationNotMetError)
63
63
  end
64
+
65
+ it "should convert a string to an integer for count" do
66
+ @body.should have_selector("li", :count => "3")
67
+ end
64
68
  end
65
69
 
66
70
  describe "specifying nested elements" do
@@ -168,6 +168,36 @@ describe "select" do
168
168
  click_button
169
169
  end
170
170
 
171
+ it "should find options by regexp with HTML entities" do
172
+ with_html <<-HTML
173
+ <html>
174
+ <form method="post" action="/login">
175
+ <select name="month"><option>Peanut butter &amp; jelly</option></select>
176
+ <input type="submit" />
177
+ </form>
178
+ </html>
179
+ HTML
180
+
181
+ webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
182
+ select /Peanut butter & jelly/
183
+ click_button
184
+ end
185
+
186
+ it "should not find options by regexp with HTML entities in the regexp" do
187
+ with_html <<-HTML
188
+ <html>
189
+ <form method="post" action="/login">
190
+ <select name="month"><option>Peanut butter &amp; jelly</option></select>
191
+ <input type="submit" />
192
+ </form>
193
+ </html>
194
+ HTML
195
+
196
+ lambda {
197
+ select /Peanut butter &amp; jelly/
198
+ }.should raise_error(Webrat::NotFoundError)
199
+ end
200
+
171
201
  it "should fail if no option matching the regexp exists" do
172
202
  with_html <<-HTML
173
203
  <html>
@@ -201,35 +231,47 @@ describe "select" do
201
231
  end
202
232
 
203
233
  it "should properly handle submitting HTML entities in select values" do
204
- pending "needs bug fix" do
205
- with_html <<-HTML
206
- <html>
207
- <form method="post" action="/login">
208
- <select name="month"><option>Peanut butter &amp; jelly</option></select>
209
- <input type="submit" />
210
- </form>
211
- </html>
212
- HTML
213
- webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
214
- click_button
215
- end
234
+ with_html <<-HTML
235
+ <html>
236
+ <form method="post" action="/login">
237
+ <select name="month"><option>Peanut butter &amp; jelly</option></select>
238
+ <input type="submit" />
239
+ </form>
240
+ </html>
241
+ HTML
242
+
243
+ webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
244
+ click_button
216
245
  end
217
246
 
218
247
  it "should properly handle locating with HTML entities in select values" do
219
- pending "needs bug fix" do
220
- with_html <<-HTML
221
- <html>
222
- <form method="post" action="/login">
223
- <select name="month"><option>Peanut butter &amp; jelly</option></select>
224
- <input type="submit" />
225
- </form>
226
- </html>
227
- HTML
228
-
229
- lambda {
230
- select "Peanut butter & jelly"
231
- }.should_not raise_error(Webrat::NotFoundError)
232
- end
248
+ with_html <<-HTML
249
+ <html>
250
+ <form method="post" action="/login">
251
+ <select name="month"><option>Peanut butter &amp; jelly</option></select>
252
+ <input type="submit" />
253
+ </form>
254
+ </html>
255
+ HTML
256
+
257
+ webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
258
+ select "Peanut butter & jelly"
259
+ click_button
260
+ end
261
+
262
+ it "should not locate based on HTML entities" do
263
+ with_html <<-HTML
264
+ <html>
265
+ <form method="post" action="/login">
266
+ <select name="month"><option>Peanut butter &amp; jelly</option></select>
267
+ <input type="submit" />
268
+ </form>
269
+ </html>
270
+ HTML
271
+
272
+ lambda {
273
+ select "Peanut butter &amp; jelly"
274
+ }.should raise_error(Webrat::NotFoundError)
233
275
  end
234
276
 
235
277
  it "should submit duplicates selected options as a single value" do
@@ -246,4 +288,168 @@ describe "select" do
246
288
  click_button
247
289
  end
248
290
 
291
+ it "should allow fields to be unselected" do
292
+ with_html <<-HTML
293
+ <html>
294
+ <form method="post" action="/login">
295
+ <select name="clothes">
296
+ <option value="tshirt" selected="selected">tshirt</option>
297
+ <option value="pants">pants</option>
298
+ </select>
299
+ <input type="submit" />
300
+ </form>
301
+ </html>
302
+ HTML
303
+
304
+ webrat_session.should_receive(:post).with("/login", {"clothes"=>""})
305
+ unselect "tshirt"
306
+ click_button
307
+ end
308
+
309
+ #
310
+ # Mutliple Selection Fields
311
+ #
312
+
313
+ it "should not submit any values for multiples without any selected" do
314
+ with_html <<-HTML
315
+ <html>
316
+ <form method="post" action="/login">
317
+ <select name="clothes[]" multiple="multiple">
318
+ <option value="tshirt">tshirt</option>
319
+ <option value="pants">pants</option>
320
+ </select>
321
+ <input type="submit" />
322
+ </form>
323
+ </html>
324
+ HTML
325
+
326
+ webrat_session.should_receive(:post).with("/login", {})
327
+ click_button
328
+ end
329
+
330
+ it "should submit with preselected values" do
331
+ with_html <<-HTML
332
+ <html>
333
+ <form method="post" action="/login">
334
+ <select name="clothes[]" multiple="multiple">
335
+ <option value="tshirt" selected="selected">tshirt</option>
336
+ <option value="pants" selected="selected">pants</option>
337
+ </select>
338
+ <input type="submit" />
339
+ </form>
340
+ </html>
341
+ HTML
342
+
343
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['tshirt', 'pants'])
344
+ click_button
345
+ end
346
+
347
+ it "should allow selection of multiple fields" do
348
+ with_html <<-HTML
349
+ <html>
350
+ <form method="post" action="/login">
351
+ <select name="clothes[]" multiple="multiple">
352
+ <option value="tshirt">tshirt</option>
353
+ <option value="pants">pants</option>
354
+ </select>
355
+ <input type="submit" />
356
+ </form>
357
+ </html>
358
+ HTML
359
+
360
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['pants'])
361
+ select 'pants'
362
+ click_button
363
+ end
364
+
365
+ it "should not overwrite preselected multiples" do
366
+ with_html <<-HTML
367
+ <html>
368
+ <form method="post" action="/login">
369
+ <select name="clothes[]" multiple="multiple">
370
+ <option value="tshirt" selected="selected">tshirt</option>
371
+ <option value="pants">pants</option>
372
+ </select>
373
+ <input type="submit" />
374
+ </form>
375
+ </html>
376
+ HTML
377
+
378
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['tshirt', 'pants'])
379
+ select 'pants'
380
+ click_button
381
+ end
382
+
383
+ it "should allow fields that exist to be selected or throw errors" do
384
+ with_html <<-HTML
385
+ <html>
386
+ <form method="post" action="/login">
387
+ <select name="clothes[]" multiple="multiple">
388
+ <option value="top" selected="selected">shirt</option>
389
+ <option value="pants">trousers</option>
390
+ </select>
391
+ <input type="submit" />
392
+ </form>
393
+ </html>
394
+ HTML
395
+
396
+ lambda { select "shirt" }.should_not raise_error(Webrat::NotFoundError)
397
+ lambda { select "trousers" }.should_not raise_error(Webrat::NotFoundError)
398
+ lambda { select "shoes" }.should raise_error(Webrat::NotFoundError)
399
+ end
400
+
401
+ it "should allow selected fields to be unselected" do
402
+ with_html <<-HTML
403
+ <html>
404
+ <form method="post" action="/login">
405
+ <select name="clothes[]" multiple="multiple">
406
+ <option value="tshirt" selected="selected">tshirt</option>
407
+ <option value="pants" selected="selected">pants</option>
408
+ </select>
409
+ <input type="submit" />
410
+ </form>
411
+ </html>
412
+ HTML
413
+
414
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['pants'])
415
+ unselect 'tshirt'
416
+ click_button
417
+ end
418
+
419
+ it "should be able to select options with special characters" do
420
+ with_html <<-HTML
421
+ <html>
422
+ <form method="post" action="/login">
423
+ <select name="clothes[]" multiple="multiple">
424
+ <option>tshirt &amp; sweater</option>
425
+ <option>pants &amp; socks</option>
426
+ </select>
427
+ <input type="submit" />
428
+ </form>
429
+ </html>
430
+ HTML
431
+
432
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['pants & socks'])
433
+ select 'pants & socks'
434
+ click_button
435
+ end
436
+
437
+ it "should be able to unselect options with special characters" do
438
+ with_html <<-HTML
439
+ <html>
440
+ <form method="post" action="/login">
441
+ <select name="clothes[]" multiple="multiple">
442
+ <option selected="selected">tshirt &amp; sweater</option>
443
+ <option selected="selected">pants &amp; socks</option>
444
+ </select>
445
+ <input type="submit" />
446
+ </form>
447
+ </html>
448
+ HTML
449
+
450
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['tshirt & sweater'])
451
+ unselect 'pants & socks'
452
+ click_button
453
+ end
454
+
249
455
  end