yannp-capybara 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/History.txt +112 -0
  2. data/README.rdoc +442 -0
  3. data/lib/capybara/cucumber.rb +32 -0
  4. data/lib/capybara/driver/base.rb +56 -0
  5. data/lib/capybara/driver/celerity_driver.rb +154 -0
  6. data/lib/capybara/driver/culerity_driver.rb +26 -0
  7. data/lib/capybara/driver/node.rb +66 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +279 -0
  9. data/lib/capybara/driver/selenium_driver.rb +157 -0
  10. data/lib/capybara/dsl.rb +98 -0
  11. data/lib/capybara/node/actions.rb +156 -0
  12. data/lib/capybara/node/finders.rb +155 -0
  13. data/lib/capybara/node/matchers.rb +97 -0
  14. data/lib/capybara/node.rb +209 -0
  15. data/lib/capybara/rails.rb +17 -0
  16. data/lib/capybara/server.rb +101 -0
  17. data/lib/capybara/session.rb +278 -0
  18. data/lib/capybara/spec/driver.rb +190 -0
  19. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  20. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  21. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  22. data/lib/capybara/spec/public/jquery.js +19 -0
  23. data/lib/capybara/spec/public/test.js +33 -0
  24. data/lib/capybara/spec/session/all_spec.rb +73 -0
  25. data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
  26. data/lib/capybara/spec/session/check_spec.rb +67 -0
  27. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  28. data/lib/capybara/spec/session/click_button_spec.rb +243 -0
  29. data/lib/capybara/spec/session/click_link_or_button_spec.rb +30 -0
  30. data/lib/capybara/spec/session/click_link_spec.rb +108 -0
  31. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  32. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  33. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  34. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  35. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  36. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  37. data/lib/capybara/spec/session/find_spec.rb +91 -0
  38. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  39. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  40. data/lib/capybara/spec/session/has_css_spec.rb +107 -0
  41. data/lib/capybara/spec/session/has_field_spec.rb +96 -0
  42. data/lib/capybara/spec/session/has_link_spec.rb +33 -0
  43. data/lib/capybara/spec/session/has_select_spec.rb +89 -0
  44. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  45. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  46. data/lib/capybara/spec/session/headers.rb +19 -0
  47. data/lib/capybara/spec/session/javascript.rb +232 -0
  48. data/lib/capybara/spec/session/response_code.rb +19 -0
  49. data/lib/capybara/spec/session/select_spec.rb +91 -0
  50. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  51. data/lib/capybara/spec/session/unselect_spec.rb +54 -0
  52. data/lib/capybara/spec/session/within_spec.rb +153 -0
  53. data/lib/capybara/spec/session.rb +78 -0
  54. data/lib/capybara/spec/test_app.rb +94 -0
  55. data/lib/capybara/spec/views/buttons.erb +4 -0
  56. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  57. data/lib/capybara/spec/views/form.erb +245 -0
  58. data/lib/capybara/spec/views/frame_one.erb +8 -0
  59. data/lib/capybara/spec/views/frame_two.erb +8 -0
  60. data/lib/capybara/spec/views/postback.erb +13 -0
  61. data/lib/capybara/spec/views/tables.erb +122 -0
  62. data/lib/capybara/spec/views/with_html.erb +43 -0
  63. data/lib/capybara/spec/views/with_js.erb +39 -0
  64. data/lib/capybara/spec/views/with_scope.erb +36 -0
  65. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  66. data/lib/capybara/spec/views/within_frames.erb +10 -0
  67. data/lib/capybara/util/save_and_open_page.rb +36 -0
  68. data/lib/capybara/util/timeout.rb +27 -0
  69. data/lib/capybara/version.rb +3 -0
  70. data/lib/capybara/xpath.rb +182 -0
  71. data/lib/capybara.rb +73 -0
  72. data/spec/capybara_spec.rb +18 -0
  73. data/spec/driver/celerity_driver_spec.rb +17 -0
  74. data/spec/driver/culerity_driver_spec.rb +13 -0
  75. data/spec/driver/rack_test_driver_spec.rb +19 -0
  76. data/spec/driver/remote_culerity_driver_spec.rb +24 -0
  77. data/spec/driver/remote_selenium_driver_spec.rb +19 -0
  78. data/spec/driver/selenium_driver_spec.rb +13 -0
  79. data/spec/dsl_spec.rb +140 -0
  80. data/spec/save_and_open_page_spec.rb +83 -0
  81. data/spec/server_spec.rb +53 -0
  82. data/spec/session/celerity_session_spec.rb +28 -0
  83. data/spec/session/culerity_session_spec.rb +26 -0
  84. data/spec/session/rack_test_session_spec.rb +34 -0
  85. data/spec/session/selenium_session_spec.rb +26 -0
  86. data/spec/spec_helper.rb +23 -0
  87. data/spec/timeout_spec.rb +28 -0
  88. data/spec/xpath_spec.rb +173 -0
  89. metadata +314 -0
@@ -0,0 +1,123 @@
1
+ shared_examples_for "has_xpath" do
2
+ describe '#has_xpath?' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ @session.should have_xpath("//p")
9
+ @session.should have_xpath("//p//a[@id='foo']")
10
+ @session.should have_xpath("//p[contains(.,'est')]")
11
+ end
12
+
13
+ it "should be false if the given selector is not on the page" do
14
+ @session.should_not have_xpath("//abbr")
15
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
16
+ @session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
17
+ end
18
+
19
+ it "should use xpath even if default selector is CSS" do
20
+ Capybara.default_selector = :css
21
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
22
+ end
23
+
24
+ it "should respect scopes" do
25
+ @session.within "//p[@id='first']" do
26
+ @session.should have_xpath(".//a[@id='foo']")
27
+ @session.should_not have_xpath(".//a[@id='red']")
28
+ end
29
+ end
30
+
31
+ context "with count" do
32
+ it "should be true if the content is on the page the given number of times" do
33
+ @session.should have_xpath("//p", :count => 3)
34
+ @session.should have_xpath("//p//a[@id='foo']", :count => 1)
35
+ @session.should have_xpath("//p[contains(.,'est')]", :count => 1)
36
+ end
37
+
38
+ it "should be false if the content is on the page the given number of times" do
39
+ @session.should_not have_xpath("//p", :count => 6)
40
+ @session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
41
+ @session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
42
+ end
43
+
44
+ it "should be false if the content isn't on the page at all" do
45
+ @session.should_not have_xpath("//abbr", :count => 2)
46
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
47
+ end
48
+ end
49
+
50
+ context "with text" do
51
+ it "should discard all matches where the given string is not contained" do
52
+ @session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
53
+ @session.should_not have_xpath("//p", :text => "Doesnotexist")
54
+ end
55
+
56
+ it "should discard all matches where the given regexp is not matched" do
57
+ @session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
58
+ @session.should_not have_xpath("//p//a", :text => /Red$/)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#has_no_xpath?' do
64
+ before do
65
+ @session.visit('/with_html')
66
+ end
67
+
68
+ it "should be false if the given selector is on the page" do
69
+ @session.should_not have_no_xpath("//p")
70
+ @session.should_not have_no_xpath("//p//a[@id='foo']")
71
+ @session.should_not have_no_xpath("//p[contains(.,'est')]")
72
+ end
73
+
74
+ it "should be true if the given selector is not on the page" do
75
+ @session.should have_no_xpath("//abbr")
76
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
77
+ @session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
78
+ end
79
+
80
+ it "should use xpath even if default selector is CSS" do
81
+ Capybara.default_selector = :css
82
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
83
+ end
84
+
85
+ it "should respect scopes" do
86
+ @session.within "//p[@id='first']" do
87
+ @session.should_not have_no_xpath(".//a[@id='foo']")
88
+ @session.should have_no_xpath(".//a[@id='red']")
89
+ end
90
+ end
91
+
92
+ context "with count" do
93
+ it "should be false if the content is on the page the given number of times" do
94
+ @session.should_not have_no_xpath("//p", :count => 3)
95
+ @session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
96
+ @session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
97
+ end
98
+
99
+ it "should be true if the content is on the page the wrong number of times" do
100
+ @session.should have_no_xpath("//p", :count => 6)
101
+ @session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
102
+ @session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
103
+ end
104
+
105
+ it "should be true if the content isn't on the page at all" do
106
+ @session.should have_no_xpath("//abbr", :count => 2)
107
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
108
+ end
109
+ end
110
+
111
+ context "with text" do
112
+ it "should discard all matches where the given string is contained" do
113
+ @session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
114
+ @session.should have_no_xpath("//p", :text => "Doesnotexist")
115
+ end
116
+
117
+ it "should discard all matches where the given regexp is matched" do
118
+ @session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
119
+ @session.should have_no_xpath("//p//a", :text => /Red$/)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with headers support" do
2
+ describe '#response_headers' do
3
+ it "should return response headers" do
4
+ @session.visit('/with_simple_html')
5
+ @session.response_headers['Content-Type'].should == 'text/html'
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without headers support" do
11
+ describe "#response_headers" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.response_headers
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,232 @@
1
+ shared_examples_for "session with javascript support" do
2
+ describe 'all JS specs' do
3
+ before do
4
+ Capybara.default_wait_time = 1
5
+ end
6
+
7
+ after do
8
+ Capybara.default_wait_time = 0
9
+ end
10
+
11
+ describe '#drag' do
12
+ it "should drag and drop an object" do
13
+ pending "drag/drop is currently broken under celerity/culerity" if @session.driver.is_a?(Capybara::Driver::Celerity)
14
+ @session.visit('/with_js')
15
+ @session.drag('//div[@id="drag"]', '//div[@id="drop"]')
16
+ @session.find('//div[contains(., "Dropped!")]').should_not be_nil
17
+ end
18
+ end
19
+
20
+ describe 'Node#drag_to' do
21
+ it "should drag and drop an object" do
22
+ pending "drag/drop is currently broken under celerity/culerity" if @session.driver.is_a?(Capybara::Driver::Celerity)
23
+ @session.visit('/with_js')
24
+ element = @session.find('//div[@id="drag"]')
25
+ target = @session.find('//div[@id="drop"]')
26
+ element.drag_to(target)
27
+ @session.find('//div[contains(., "Dropped!")]').should_not be_nil
28
+ end
29
+ end
30
+
31
+ describe '#find' do
32
+ it "should allow triggering of custom JS events" do
33
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
34
+ @session.visit('/with_js')
35
+ @session.find(:css, '#with_focus_event').trigger(:focus)
36
+ @session.should have_css('#focus_event_triggered')
37
+ end
38
+ end
39
+
40
+ describe '#body' do
41
+ it "should return the current state of the page" do
42
+ @session.visit('/with_js')
43
+ @session.body.should include('I changed it')
44
+ @session.body.should_not include('This is text')
45
+ end
46
+ end
47
+
48
+ describe '#source' do
49
+ it "should return the original, unmodified source of the page" do
50
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
51
+ @session.visit('/with_js')
52
+ @session.source.should include('This is text')
53
+ @session.source.should_not include('I changed it')
54
+ end
55
+ end
56
+
57
+ describe "#evaluate_script" do
58
+ it "should evaluate the given script and return whatever it produces" do
59
+ @session.visit('/with_js')
60
+ @session.evaluate_script("1+3").should == 4
61
+ end
62
+ end
63
+
64
+ describe "#execute_script" do
65
+ it "should execute the given script and return nothing" do
66
+ @session.visit('/with_js')
67
+ @session.execute_script("$('#change').text('Funky Doodle')").should be_nil
68
+ @session.should have_css('#change', :text => 'Funky Doodle')
69
+ end
70
+ end
71
+
72
+ describe '#find' do
73
+ it "should wait for asynchronous load" do
74
+ @session.visit('/with_js')
75
+ @session.click_link('Click me')
76
+ @session.find("//a[contains(.,'Has been clicked')]")[:href].should == '#'
77
+ end
78
+ end
79
+
80
+ describe '#wait_until' do
81
+ before do
82
+ @default_timeout = Capybara.default_wait_time
83
+ end
84
+
85
+ after do
86
+ Capybara.default_wait_time = @default_wait_time
87
+ end
88
+
89
+ it "should wait for block to return true" do
90
+ @session.visit('/with_js')
91
+ @session.select('My Waiting Option', :from => 'waiter')
92
+ @session.evaluate_script('activeRequests == 1').should be_true
93
+ @session.wait_until do
94
+ @session.evaluate_script('activeRequests == 0')
95
+ end
96
+ @session.evaluate_script('activeRequests == 0').should be_true
97
+ end
98
+
99
+ it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
100
+ @session.visit('/with_html')
101
+ Proc.new do
102
+ @session.wait_until(0.1) do
103
+ @session.all('//div[@id="nosuchthing"]').first
104
+ end
105
+ end.should raise_error(::Capybara::TimeoutError)
106
+ end
107
+
108
+ it "should accept custom timeout in seconds" do
109
+ start = Time.now
110
+ Capybara.default_wait_time = 5
111
+ begin
112
+ @session.wait_until(0.1) { false }
113
+ rescue Capybara::TimeoutError; end
114
+ (Time.now - start).should be_close(0.1, 0.1)
115
+ end
116
+
117
+ it "should default to Capybara.default_wait_time before timeout" do
118
+ @session.driver # init the driver to exclude init timing from test
119
+ start = Time.now
120
+ Capybara.default_wait_time = 0.2
121
+ begin
122
+ @session.wait_until { false }
123
+ rescue Capybara::TimeoutError; end
124
+ if @session.driver.has_shortcircuit_timeout?
125
+ (Time.now - start).should be_close(0, 0.1)
126
+ else
127
+ (Time.now - start).should be_close(0.2, 0.1)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#click_link_or_button' do
133
+ it "should wait for asynchronous load" do
134
+ @session.visit('/with_js')
135
+ @session.click_link('Click me')
136
+ @session.click_link_or_button('Has been clicked')
137
+ end
138
+ end
139
+
140
+ describe '#click_link' do
141
+ it "should wait for asynchronous load" do
142
+ @session.visit('/with_js')
143
+ @session.click_link('Click me')
144
+ @session.click_link('Has been clicked')
145
+ end
146
+ end
147
+
148
+ describe '#click_button' do
149
+ it "should wait for asynchronous load" do
150
+ @session.visit('/with_js')
151
+ @session.click_link('Click me')
152
+ @session.click_button('New Here')
153
+ end
154
+ end
155
+
156
+ describe '#fill_in' do
157
+ it "should wait for asynchronous load" do
158
+ @session.visit('/with_js')
159
+ @session.click_link('Click me')
160
+ @session.fill_in('new_field', :with => 'Testing...')
161
+ end
162
+ end
163
+
164
+ describe '#check' do
165
+ it "should trigger associated events" do
166
+ @session.visit('/with_js')
167
+ @session.check('checkbox_with_event')
168
+ @session.should have_css('#checkbox_event_triggered');
169
+ end
170
+ end
171
+
172
+ describe '#has_xpath?' do
173
+ it "should wait for content to appear" do
174
+ @session.visit('/with_js')
175
+ @session.click_link('Click me')
176
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
177
+ end
178
+ end
179
+
180
+ describe '#has_no_xpath?' do
181
+ it "should wait for content to disappear" do
182
+ @session.visit('/with_js')
183
+ @session.click_link('Click me')
184
+ @session.should have_no_xpath("//p[@id='change']")
185
+ end
186
+ end
187
+
188
+ describe '#has_css?' do
189
+ it "should wait for content to appear" do
190
+ @session.visit('/with_js')
191
+ @session.click_link('Click me')
192
+ @session.should have_css("input[type='submit'][value='New Here']")
193
+ end
194
+ end
195
+
196
+ describe '#has_no_xpath?' do
197
+ it "should wait for content to disappear" do
198
+ @session.visit('/with_js')
199
+ @session.click_link('Click me')
200
+ @session.should have_no_css("p#change")
201
+ end
202
+ end
203
+
204
+ describe '#has_content?' do
205
+ it "should wait for content to appear" do
206
+ @session.visit('/with_js')
207
+ @session.click_link('Click me')
208
+ @session.should have_content("Has been clicked")
209
+ end
210
+ end
211
+
212
+ describe '#has_no_content?' do
213
+ it "should wait for content to disappear" do
214
+ @session.visit('/with_js')
215
+ @session.click_link('Click me')
216
+ @session.should have_no_content("I changed it")
217
+ end
218
+ end
219
+
220
+ end
221
+ end
222
+
223
+ shared_examples_for "session without javascript support" do
224
+ describe "#evaluate_script" do
225
+ before{ @session.visit('/with_simple_html') }
226
+ it "should raise an error" do
227
+ running {
228
+ @session.evaluate_script('3 + 3')
229
+ }.should raise_error(Capybara::NotSupportedByDriverError)
230
+ end
231
+ end
232
+ end
@@ -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,91 @@
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 select an option from a select box by id" do
17
+ @session.select("Finish", :from => 'form_locale')
18
+ @session.click_button('awesome')
19
+ extract_results(@session)['locale'].should == 'fi'
20
+ end
21
+
22
+ it "should select an option from a select box by label" do
23
+ @session.select("Finish", :from => 'Locale')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['locale'].should == 'fi'
26
+ end
27
+
28
+ it "should favour exact matches to option labels" do
29
+ @session.select("Mr", :from => 'Title')
30
+ @session.click_button('awesome')
31
+ extract_results(@session)['title'].should == 'Mr'
32
+ end
33
+
34
+ it "should escape quotes" do
35
+ @session.select("John's made-up language", :from => 'Locale')
36
+ @session.click_button('awesome')
37
+ extract_results(@session)['locale'].should == 'jo'
38
+ end
39
+
40
+ it "should obey from" do
41
+ @session.select("Miss", :from => "Other title")
42
+ @session.click_button('awesome')
43
+ results = extract_results(@session)
44
+ results['other_title'].should == "Miss"
45
+ results['title'].should_not == "Miss"
46
+ end
47
+
48
+ it "show match labels with preceding or trailing whitespace" do
49
+ @session.select("Lojban", :from => 'Locale')
50
+ @session.click_button('awesome')
51
+ extract_results(@session)['locale'].should == 'jbo'
52
+ end
53
+
54
+ context "with a locator that doesn't exist" do
55
+ it "should raise an error" do
56
+ running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
57
+ end
58
+ end
59
+
60
+ context "with an option that doesn't exist" do
61
+ it "should raise an error" do
62
+ running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
63
+ end
64
+ end
65
+
66
+ context "with multiple select" do
67
+ it "should return an empty value" do
68
+ @session.find_field('Language').value.should == []
69
+ end
70
+
71
+ it "should return value of the selected options" do
72
+ @session.select("Ruby", :from => 'Language')
73
+ @session.select("Javascript", :from => 'Language')
74
+ @session.find_field('Language').value.should include('Ruby', 'Javascript')
75
+ end
76
+
77
+ it "should select one option" do
78
+ @session.select("Ruby", :from => 'Language')
79
+ @session.click_button('awesome')
80
+ extract_results(@session)['languages'].should == ['Ruby']
81
+ end
82
+
83
+ it "should select multiple options" do
84
+ @session.select("Ruby", :from => 'Language')
85
+ @session.select("Javascript", :from => 'Language')
86
+ @session.click_button('awesome')
87
+ extract_results(@session)['languages'].should include('Ruby', 'Javascript')
88
+ end
89
+ end
90
+ end
91
+ 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,54 @@
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 from a select box by label" do
16
+ @session.unselect('Commando', :from => 'Underwear')
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 favour exact matches to option labels" do
23
+ @session.unselect("Briefs", :from => 'Underwear')
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
26
+ extract_results(@session)['underwear'].should_not include('Briefs')
27
+ end
28
+
29
+ it "should escape quotes" do
30
+ @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
31
+ @session.click_button('awesome')
32
+ extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
33
+ end
34
+ end
35
+
36
+ context "with single select" do
37
+ it "should raise an error" do
38
+ running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
39
+ end
40
+ end
41
+
42
+ context "with a locator that doesn't exist" do
43
+ it "should raise an error" do
44
+ running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
45
+ end
46
+ end
47
+
48
+ context "with an option that doesn't exist" do
49
+ it "should raise an error" do
50
+ running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::OptionNotFound)
51
+ end
52
+ end
53
+ end
54
+ end