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.
- data/.gitignore +4 -1
- data/Gemfile +19 -0
- data/History.txt +29 -0
- data/Rakefile +27 -63
- data/Thorfile +117 -0
- data/lib/webrat.rb +11 -3
- data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +0 -0
- data/lib/webrat/adapters/merb.rb +11 -0
- data/lib/webrat/{rack.rb → adapters/rack.rb} +0 -0
- data/lib/webrat/{rails.rb → adapters/rails.rb} +2 -23
- data/lib/webrat/{sinatra.rb → adapters/sinatra.rb} +0 -2
- data/lib/webrat/core.rb +0 -1
- data/lib/webrat/core/configuration.rb +6 -16
- data/lib/webrat/core/elements/area.rb +2 -2
- data/lib/webrat/core/elements/element.rb +3 -3
- data/lib/webrat/core/elements/field.rb +106 -30
- data/lib/webrat/core/elements/form.rb +4 -4
- data/lib/webrat/core/elements/label.rb +4 -4
- data/lib/webrat/core/elements/link.rb +6 -6
- data/lib/webrat/core/elements/select_option.rb +15 -2
- data/lib/webrat/core/locators.rb +1 -1
- data/lib/webrat/core/locators/area_locator.rb +3 -3
- data/lib/webrat/core/locators/button_locator.rb +6 -6
- data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
- data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
- data/lib/webrat/core/locators/field_named_locator.rb +3 -3
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +2 -2
- data/lib/webrat/core/locators/link_locator.rb +7 -7
- data/lib/webrat/core/locators/select_option_locator.rb +5 -5
- data/lib/webrat/core/logging.rb +4 -5
- data/lib/webrat/core/matchers/have_content.rb +2 -7
- data/lib/webrat/core/matchers/have_xpath.rb +3 -28
- data/lib/webrat/core/methods.rb +1 -0
- data/lib/webrat/core/scope.rb +17 -2
- data/lib/webrat/core/session.rb +2 -1
- data/lib/webrat/core/xml.rb +41 -84
- data/lib/webrat/integrations/merb.rb +10 -0
- data/lib/webrat/integrations/rails.rb +25 -0
- data/lib/webrat/integrations/rspec-rails.rb +11 -0
- data/lib/webrat/integrations/selenium.rb +11 -0
- data/lib/webrat/rspec-rails.rb +2 -10
- data/lib/webrat/selenium.rb +0 -10
- data/lib/webrat/selenium/application_servers.rb +1 -1
- data/lib/webrat/selenium/application_servers/external.rb +1 -1
- data/lib/webrat/selenium/location_strategy_javascript/label.js +29 -3
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
- data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
- data/lib/webrat/selenium/selenium_session.rb +21 -2
- data/lib/webrat/selenium/silence_stream.rb +1 -1
- data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
- data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
- data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
- data/spec/integration/rails/config/environment.rb +1 -1
- data/spec/integration/rails/config/routes.rb +1 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
- data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
- data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
- data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
- data/spec/integration/rails/test/test_helper.rb +1 -0
- data/spec/private/core/configuration_spec.rb +2 -31
- data/spec/private/core/field_spec.rb +14 -16
- data/spec/private/mechanize/mechanize_adapter_spec.rb +0 -2
- data/spec/private/nokogiri_spec.rb +2 -2
- data/spec/private/rails/rails_adapter_spec.rb +0 -27
- data/spec/public/basic_auth_spec.rb +13 -2
- data/spec/public/click_button_spec.rb +10 -12
- data/spec/public/click_link_spec.rb +21 -0
- data/spec/public/fill_in_spec.rb +15 -0
- data/spec/public/matchers/have_selector_spec.rb +4 -0
- data/spec/public/select_spec.rb +232 -26
- data/spec/spec_helper.rb +2 -0
- data/webrat.gemspec +305 -313
- metadata +21 -25
- data/VERSION +0 -1
- data/lib/webrat/core/xml/hpricot.rb +0 -19
- data/lib/webrat/core/xml/nokogiri.rb +0 -76
- data/lib/webrat/core/xml/rexml.rb +0 -24
- data/lib/webrat/merb_adapter.rb +0 -82
- data/lib/webrat/merb_multipart_support.rb +0 -27
- data/spec/private/core/logging_spec.rb +0 -10
- data/spec/private/merb/attaches_file_spec.rb +0 -93
- data/spec/private/merb/merb_adapter_spec.rb +0 -61
@@ -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
|
-
|
6
|
-
|
7
|
-
html
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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,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
|
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
|
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
|
-
|
335
|
-
|
336
|
-
|
337
|
-
<
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
click_button
|
345
|
-
end
|
334
|
+
with_html <<-HTML
|
335
|
+
<html>
|
336
|
+
<form method="post" action="/posts">
|
337
|
+
<textarea name="post[body]">Peanut butter & 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>
|
data/spec/public/fill_in_spec.rb
CHANGED
@@ -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
|
data/spec/public/select_spec.rb
CHANGED
@@ -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 & 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 & jelly</option></select>
|
191
|
+
<input type="submit" />
|
192
|
+
</form>
|
193
|
+
</html>
|
194
|
+
HTML
|
195
|
+
|
196
|
+
lambda {
|
197
|
+
select /Peanut butter & 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
|
-
|
205
|
-
|
206
|
-
|
207
|
-
<
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end
|
234
|
+
with_html <<-HTML
|
235
|
+
<html>
|
236
|
+
<form method="post" action="/login">
|
237
|
+
<select name="month"><option>Peanut butter & 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
|
-
|
220
|
-
|
221
|
-
|
222
|
-
<
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
248
|
+
with_html <<-HTML
|
249
|
+
<html>
|
250
|
+
<form method="post" action="/login">
|
251
|
+
<select name="month"><option>Peanut butter & 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 & jelly</option></select>
|
267
|
+
<input type="submit" />
|
268
|
+
</form>
|
269
|
+
</html>
|
270
|
+
HTML
|
271
|
+
|
272
|
+
lambda {
|
273
|
+
select "Peanut butter & 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 & sweater</option>
|
425
|
+
<option>pants & 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 & sweater</option>
|
443
|
+
<option selected="selected">pants & 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
|