capybara_minitest_spec 0.1.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 (70) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +7 -0
  6. data/README.md +31 -0
  7. data/Rakefile +9 -0
  8. data/capybara_minitest_spec.gemspec +25 -0
  9. data/lib/capybara_minitest_spec/version.rb +3 -0
  10. data/lib/capybara_minitest_spec.rb +45 -0
  11. data/test/matchers_spec.rb +447 -0
  12. data/test/spec_helper.rb +28 -0
  13. data/test_app/driver.rb +297 -0
  14. data/test_app/fixtures/capybara.jpg +3 -0
  15. data/test_app/fixtures/test_file.txt +1 -0
  16. data/test_app/public/test.js +43 -0
  17. data/test_app/session/all_spec.rb +78 -0
  18. data/test_app/session/attach_file_spec.rb +73 -0
  19. data/test_app/session/check_spec.rb +65 -0
  20. data/test_app/session/choose_spec.rb +26 -0
  21. data/test_app/session/click_button_spec.rb +304 -0
  22. data/test_app/session/click_link_or_button_spec.rb +36 -0
  23. data/test_app/session/click_link_spec.rb +119 -0
  24. data/test_app/session/current_host_spec.rb +68 -0
  25. data/test_app/session/current_url_spec.rb +15 -0
  26. data/test_app/session/fill_in_spec.rb +125 -0
  27. data/test_app/session/find_button_spec.rb +18 -0
  28. data/test_app/session/find_by_id_spec.rb +18 -0
  29. data/test_app/session/find_field_spec.rb +26 -0
  30. data/test_app/session/find_link_spec.rb +19 -0
  31. data/test_app/session/find_spec.rb +149 -0
  32. data/test_app/session/first_spec.rb +105 -0
  33. data/test_app/session/has_button_spec.rb +32 -0
  34. data/test_app/session/has_content_spec.rb +106 -0
  35. data/test_app/session/has_css_spec.rb +243 -0
  36. data/test_app/session/has_field_spec.rb +192 -0
  37. data/test_app/session/has_link_spec.rb +37 -0
  38. data/test_app/session/has_select_spec.rb +129 -0
  39. data/test_app/session/has_selector_spec.rb +129 -0
  40. data/test_app/session/has_table_spec.rb +96 -0
  41. data/test_app/session/has_xpath_spec.rb +123 -0
  42. data/test_app/session/headers.rb +19 -0
  43. data/test_app/session/javascript.rb +289 -0
  44. data/test_app/session/response_code.rb +19 -0
  45. data/test_app/session/select_spec.rb +113 -0
  46. data/test_app/session/text_spec.rb +19 -0
  47. data/test_app/session/uncheck_spec.rb +21 -0
  48. data/test_app/session/unselect_spec.rb +61 -0
  49. data/test_app/session/within_spec.rb +178 -0
  50. data/test_app/session.rb +154 -0
  51. data/test_app/test_app.rb +142 -0
  52. data/test_app/views/buttons.erb +4 -0
  53. data/test_app/views/fieldsets.erb +29 -0
  54. data/test_app/views/form.erb +365 -0
  55. data/test_app/views/frame_one.erb +8 -0
  56. data/test_app/views/frame_two.erb +8 -0
  57. data/test_app/views/header_links.erb +7 -0
  58. data/test_app/views/host_links.erb +12 -0
  59. data/test_app/views/popup_one.erb +8 -0
  60. data/test_app/views/popup_two.erb +8 -0
  61. data/test_app/views/postback.erb +13 -0
  62. data/test_app/views/tables.erb +122 -0
  63. data/test_app/views/with_html.erb +74 -0
  64. data/test_app/views/with_html_entities.erb +1 -0
  65. data/test_app/views/with_js.erb +48 -0
  66. data/test_app/views/with_scope.erb +36 -0
  67. data/test_app/views/with_simple_html.erb +1 -0
  68. data/test_app/views/within_frames.erb +10 -0
  69. data/test_app/views/within_popups.erb +25 -0
  70. metadata +158 -0
@@ -0,0 +1,297 @@
1
+ require 'capybara/spec/test_app'
2
+
3
+ shared_examples_for 'driver' do
4
+
5
+ describe '#visit' do
6
+ it "should move to another page" do
7
+ @driver.visit('/')
8
+ @driver.body.should include('Hello world!')
9
+ @driver.visit('/foo')
10
+ @driver.body.should include('Another World')
11
+ end
12
+
13
+ it "should show the correct URL" do
14
+ @driver.visit('/foo')
15
+ @driver.current_url.should include('/foo')
16
+ end
17
+ end
18
+
19
+ describe '#body' do
20
+ it "should return text reponses" do
21
+ @driver.visit('/')
22
+ @driver.body.should include('Hello world!')
23
+ end
24
+
25
+ it "should return the full response html" do
26
+ @driver.visit('/with_simple_html')
27
+ @driver.body.should include('Bar')
28
+ end
29
+
30
+ if "".respond_to?(:encoding)
31
+ context "encoding of response between ascii and utf8" do
32
+ it "should be valid with html entities" do
33
+ @driver.visit('/with_html_entities')
34
+ lambda { @driver.body.encode!("UTF-8") }.should_not raise_error
35
+ end
36
+
37
+ it "should be valid without html entities" do
38
+ @driver.visit('/with_html')
39
+ lambda { @driver.body.encode!("UTF-8") }.should_not raise_error
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#find' do
46
+ context "with xpath selector" do
47
+ before do
48
+ @driver.visit('/with_html')
49
+ end
50
+
51
+ it "should extract node texts" do
52
+ @driver.find('//a')[0].text.should == 'labore'
53
+ @driver.find('//a')[1].text.should == 'ullamco'
54
+ end
55
+
56
+ it "should extract node attributes" do
57
+ @driver.find('//a')[0][:class].should == 'simple'
58
+ @driver.find('//a')[1][:id].should == 'foo'
59
+ @driver.find('//input')[0][:type].should == 'text'
60
+ end
61
+
62
+ it "should extract boolean node attributes" do
63
+ @driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
64
+ end
65
+
66
+ it "should allow retrieval of the value" do
67
+ @driver.find('//textarea').first.value.should == 'banana'
68
+ end
69
+
70
+ it "should allow assignment of field value" do
71
+ @driver.find('//input').first.value.should == 'monkey'
72
+ @driver.find('//input').first.set('gorilla')
73
+ @driver.find('//input').first.value.should == 'gorilla'
74
+ end
75
+
76
+ it "should extract node tag name" do
77
+ @driver.find('//a')[0].tag_name.should == 'a'
78
+ @driver.find('//a')[1].tag_name.should == 'a'
79
+ @driver.find('//p')[1].tag_name.should == 'p'
80
+ end
81
+
82
+ it "should extract node visibility" do
83
+ @driver.find('//a')[0].should be_visible
84
+
85
+ @driver.find('//div[@id="hidden"]')[0].should_not be_visible
86
+ @driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
87
+ end
88
+
89
+ it "should extract node checked state" do
90
+ @driver.visit('/form')
91
+ @driver.find('//input[@id="gender_female"]')[0].should be_checked
92
+ @driver.find('//input[@id="gender_male"]')[0].should_not be_checked
93
+ @driver.find('//h1')[0].should_not be_checked
94
+ end
95
+
96
+ it "should extract node selected state" do
97
+ @driver.visit('/form')
98
+ @driver.find('//option[@value="en"]')[0].should be_selected
99
+ @driver.find('//option[@value="sv"]')[0].should_not be_selected
100
+ @driver.find('//h1')[0].should_not be_selected
101
+ end
102
+
103
+ it "should return document text on /html selector" do
104
+ @driver.visit('/with_simple_html')
105
+ @driver.find('/html')[0].text.should == 'Bar'
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ shared_examples_for "driver with javascript support" do
112
+ before { @driver.visit('/with_js') }
113
+
114
+ describe '#find' do
115
+ it "should find dynamically changed nodes" do
116
+ @driver.find('//p').first.text.should == 'I changed it'
117
+ end
118
+ end
119
+
120
+ describe '#drag_to' do
121
+ it "should drag and drop an object" do
122
+ draggable = @driver.find('//div[@id="drag"]').first
123
+ droppable = @driver.find('//div[@id="drop"]').first
124
+ draggable.drag_to(droppable)
125
+ @driver.find('//div[contains(., "Dropped!")]').should_not be_empty
126
+ end
127
+ end
128
+
129
+ describe "#evaluate_script" do
130
+ it "should return the value of the executed script" do
131
+ @driver.evaluate_script('1+1').should == 2
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ shared_examples_for "driver with resynchronization support" do
138
+ before { @driver.visit('/with_js') }
139
+ describe "#find" do
140
+ context "with synchronization turned on" do
141
+ before { @driver.options[:resynchronize] = true }
142
+ it "should wait for all ajax requests to finish" do
143
+ @driver.find('//input[@id="fire_ajax_request"]').first.click
144
+ @driver.find('//p[@id="ajax_request_done"]').should_not be_empty
145
+ end
146
+ end
147
+
148
+ context "with resynchronization turned off" do
149
+ before { @driver.options[:resynchronize] = false }
150
+ it "should not wait for ajax requests to finish" do
151
+ @driver.find('//input[@id="fire_ajax_request"]').first.click
152
+ @driver.find('//p[@id="ajax_request_done"]').should be_empty
153
+ end
154
+ end
155
+
156
+ context "with short synchronization timeout" do
157
+ before { @driver.options[:resynchronize] = true }
158
+ before { @driver.options[:resynchronization_timeout] = 0.1 }
159
+
160
+ it "should raise an error" do
161
+ expect do
162
+ @driver.find('//input[@id="fire_ajax_request"]').first.click
163
+ end.to raise_error(Capybara::TimeoutError, "failed to resynchronize, ajax request timed out")
164
+ end
165
+ end
166
+ end
167
+
168
+ after { @driver.options[:resynchronize] = false }
169
+ after { @driver.options[:resynchronization_timeout] = 10 }
170
+ end
171
+
172
+ shared_examples_for "driver with header support" do
173
+ it "should make headers available through response_headers" do
174
+ @driver.visit('/with_simple_html')
175
+ @driver.response_headers['Content-Type'].should =~ /text\/html/
176
+ end
177
+ end
178
+
179
+ shared_examples_for "driver with status code support" do
180
+ it "should make the status code available through status_code" do
181
+ @driver.visit('/with_simple_html')
182
+ @driver.status_code.should == 200
183
+ end
184
+ end
185
+
186
+ shared_examples_for "driver without status code support" do
187
+ it "should raise when trying to access the status code available through status_code" do
188
+ @driver.visit('/with_simple_html')
189
+ lambda {
190
+ @driver.status_code
191
+ }.should raise_error(Capybara::NotSupportedByDriverError)
192
+ end
193
+ end
194
+
195
+ shared_examples_for "driver with frame support" do
196
+ describe '#within_frame' do
197
+ before(:each) do
198
+ @driver.visit('/within_frames')
199
+ end
200
+
201
+ it "should find the div in frameOne" do
202
+ @driver.within_frame("frameOne") do
203
+ @driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
204
+ end
205
+ end
206
+ it "should find the div in FrameTwo" do
207
+ @driver.within_frame("frameTwo") do
208
+ @driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
209
+ end
210
+ end
211
+ it "should find the text div in the main window after finding text in frameOne" do
212
+ @driver.within_frame("frameOne") do
213
+ @driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
214
+ end
215
+ @driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
216
+ end
217
+ it "should find the text div in the main window after finding text in frameTwo" do
218
+ @driver.within_frame("frameTwo") do
219
+ @driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
220
+ end
221
+ @driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
222
+ end
223
+ end
224
+ end
225
+
226
+ shared_examples_for "driver with support for window switching" do
227
+ describe '#within_window' do
228
+ before(:each) do
229
+ @driver.visit('/within_popups')
230
+ end
231
+ after(:each) do
232
+ @driver.within_window("firstPopup") do
233
+ @driver.evaluate_script('window.close()')
234
+ end
235
+ @driver.within_window("secondPopup") do
236
+ @driver.evaluate_script('window.close()')
237
+ end
238
+ end
239
+
240
+ it "should find the div in firstPopup" do
241
+ @driver.within_window("firstPopup") do
242
+ @driver.find("//*[@id='divInPopupOne']")[0].text.should eql 'This is the text of divInPopupOne'
243
+ end
244
+ end
245
+ it "should find the div in secondPopup" do
246
+ @driver.within_window("secondPopup") do
247
+ @driver.find("//*[@id='divInPopupTwo']")[0].text.should eql 'This is the text of divInPopupTwo'
248
+ end
249
+ end
250
+ it "should find the divs in both popups" do
251
+ @driver.within_window("secondPopup") do
252
+ @driver.find("//*[@id='divInPopupTwo']")[0].text.should eql 'This is the text of divInPopupTwo'
253
+ end
254
+ @driver.within_window("firstPopup") do
255
+ @driver.find("//*[@id='divInPopupOne']")[0].text.should eql 'This is the text of divInPopupOne'
256
+ end
257
+ end
258
+ it "should find the div in the main window after finding a div in a popup" do
259
+ @driver.within_window("secondPopup") do
260
+ @driver.find("//*[@id='divInPopupTwo']")[0].text.should eql 'This is the text of divInPopupTwo'
261
+ end
262
+ @driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
263
+ end
264
+ end
265
+ end
266
+
267
+ shared_examples_for "driver with cookies support" do
268
+ describe "#reset!" do
269
+ it "should set and clean cookies" do
270
+ @driver.visit('/get_cookie')
271
+ @driver.body.should_not include('test_cookie')
272
+
273
+ @driver.visit('/set_cookie')
274
+ @driver.body.should include('Cookie set to test_cookie')
275
+
276
+ @driver.visit('/get_cookie')
277
+ @driver.body.should include('test_cookie')
278
+
279
+ @driver.reset!
280
+ @driver.visit('/get_cookie')
281
+ @driver.body.should_not include('test_cookie')
282
+ end
283
+ end
284
+ end
285
+
286
+ shared_examples_for "driver with infinite redirect detection" do
287
+ it "should follow 5 redirects" do
288
+ @driver.visit('/redirect/5/times')
289
+ @driver.body.should include('redirection complete')
290
+ end
291
+
292
+ it "should not follow more than 5 redirects" do
293
+ running do
294
+ @driver.visit('/redirect/6/times')
295
+ end.should raise_error(Capybara::InfiniteRedirectError)
296
+ end
297
+ end
@@ -0,0 +1,3 @@
1
+ This is a jpeg file :) Since it is rendered in the
2
+ view it doesn't actually contain any binary data,
3
+ as that would cause Nokogiri to go mad.
@@ -0,0 +1 @@
1
+ ThisIsTheTestFile
@@ -0,0 +1,43 @@
1
+ var activeRequests = 0;
2
+ $(function() {
3
+ $('#change').text('I changed it');
4
+ $('#drag').draggable();
5
+ $('#drop').droppable({
6
+ drop: function(event, ui) {
7
+ ui.draggable.remove();
8
+ $(this).html('Dropped!');
9
+ }
10
+ });
11
+ $('#clickable').click(function() {
12
+ var link = $(this);
13
+ setTimeout(function() {
14
+ $(link).after('<a id="has-been-clicked" href="#">Has been clicked</a>');
15
+ $(link).after('<input type="submit" value="New Here">');
16
+ $(link).after('<input type="text" id="new_field">');
17
+ $('#change').remove();
18
+ }, 500);
19
+ return false;
20
+ });
21
+ $('#waiter').change(function() {
22
+ activeRequests = 1;
23
+ setTimeout(function() {
24
+ activeRequests = 0;
25
+ }, 500);
26
+ });
27
+ $('#with_focus_event').focus(function() {
28
+ $('body').append('<p id="focus_event_triggered">Focus Event triggered</p>');
29
+ });
30
+ $('#checkbox_with_event').click(function() {
31
+ $('body').append('<p id="checkbox_event_triggered">Checkbox event triggered</p>');
32
+ });
33
+ $('#fire_ajax_request').click(function() {
34
+ $.ajax({url: "/slow_response", context: document.body, success: function() {
35
+ $('body').append('<p id="ajax_request_done">Ajax request done</p>');
36
+ }});
37
+ });
38
+ $('#reload-link').click(function() {
39
+ setTimeout(function() {
40
+ $('#reload-me').replaceWith('<div id="reload-me"><em><a>RELOADED</a></em></div>');
41
+ }, 250)
42
+ });
43
+ });
@@ -0,0 +1,78 @@
1
+ shared_examples_for "all" do
2
+ describe '#all' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find all elements using the given locator" do
8
+ @session.all('//p').should have(3).elements
9
+ @session.all('//h1').first.text.should == 'This is a test'
10
+ @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
11
+ end
12
+
13
+ it "should return an empty array when nothing was found" do
14
+ @session.all('//div[@id="nosuchthing"]').should be_empty
15
+ end
16
+
17
+ it "should accept an XPath instance" do
18
+ @session.visit('/form')
19
+ @xpath = XPath::HTML.fillable_field('Name')
20
+ @result = @session.all(@xpath).map { |r| r.value }
21
+ @result.should include('Smith', 'John', 'John Smith')
22
+ end
23
+
24
+ context "with css selectors" do
25
+ it "should find all elements using the given selector" do
26
+ @session.all(:css, 'h1').first.text.should == 'This is a test'
27
+ @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
28
+ end
29
+
30
+ it "should find all elements when given a list of selectors" do
31
+ @session.all(:css, 'h1, p').should have(4).elements
32
+ end
33
+ end
34
+
35
+ context "with xpath selectors" do
36
+ it "should find the first element using the given locator" do
37
+ @session.all(:xpath, '//h1').first.text.should == 'This is a test'
38
+ @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
39
+ end
40
+ end
41
+
42
+ context "with css as default selector" do
43
+ before { Capybara.default_selector = :css }
44
+ it "should find the first element using the given locator" do
45
+ @session.all('h1').first.text.should == 'This is a test'
46
+ @session.all("input[id='test_field']").first[:value].should == 'monkey'
47
+ end
48
+ after { Capybara.default_selector = :xpath }
49
+ end
50
+
51
+ context "with visible filter" do
52
+ after { Capybara.ignore_hidden_elements = false }
53
+ it "should only find visible nodes" do
54
+ @session.all("//a[@title='awesome title']").should have(2).elements
55
+ @session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
56
+ Capybara.ignore_hidden_elements = true
57
+ @session.all("//a[@title='awesome title']").should have(1).elements
58
+ end
59
+
60
+ it "should only find invisible nodes" do
61
+ Capybara.ignore_hidden_elements = true
62
+ @session.all("//a[@title='awesome title']", :visible => false).should have(2).elements
63
+ end
64
+ end
65
+
66
+ context "within a scope" do
67
+ before do
68
+ @session.visit('/with_scope')
69
+ end
70
+
71
+ it "should find any element using the given locator" do
72
+ @session.within(:xpath, "//div[@id='for_bar']") do
73
+ @session.all('.//li').should have(2).elements
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,73 @@
1
+ shared_examples_for "attach_file" do
2
+
3
+ describe "#attach_file" do
4
+ before do
5
+ @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
6
+ @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
7
+ @session.visit('/form')
8
+ end
9
+
10
+ context "with normal form" do
11
+ it "should set a file path by id" do
12
+ @session.attach_file "form_image", __FILE__
13
+ @session.click_button('awesome')
14
+ extract_results(@session)['image'].should == File.basename(__FILE__)
15
+ end
16
+
17
+ it "should set a file path by label" do
18
+ @session.attach_file "Image", __FILE__
19
+ @session.click_button('awesome')
20
+ extract_results(@session)['image'].should == File.basename(__FILE__)
21
+ end
22
+ end
23
+
24
+ context "with multipart form" do
25
+ it "should set a file path by id" do
26
+ @session.attach_file "form_document", @test_file_path
27
+ @session.click_button('Upload')
28
+ @session.body.should include(File.read(@test_file_path))
29
+ end
30
+
31
+ it "should set a file path by label" do
32
+ @session.attach_file "Document", @test_file_path
33
+ @session.click_button('Upload')
34
+ @session.body.should include(File.read(@test_file_path))
35
+ end
36
+
37
+ it "should not break if no file is submitted" do
38
+ @session.click_button('Upload')
39
+ @session.body.should include('No file uploaded')
40
+ end
41
+
42
+ it "should send content type text/plain when uploading a text file" do
43
+ @session.attach_file "Document", @test_file_path
44
+ @session.click_button 'Upload'
45
+ @session.body.should include('text/plain')
46
+ end
47
+
48
+ it "should send content type image/jpeg when uploading an image" do
49
+ @session.attach_file "Document", @test_jpg_file_path
50
+ @session.click_button 'Upload'
51
+ @session.body.should include('image/jpeg')
52
+ end
53
+
54
+ it "should not break when using HTML5 multiple file input" do
55
+ @session.attach_file "Multiple Documents", @test_file_path
56
+ @session.click_button('Upload Multiple')
57
+ @session.body.should include(File.read(@test_file_path))
58
+ end
59
+ end
60
+
61
+ context "with a locator that doesn't exist" do
62
+ it "should raise an error" do
63
+ running { @session.attach_file('does not exist', @test_file_path) }.should raise_error(Capybara::ElementNotFound)
64
+ end
65
+ end
66
+
67
+ context "with a path that doesn't exist" do
68
+ it "should raise an error" do
69
+ running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,65 @@
1
+ shared_examples_for "check" do
2
+
3
+ describe "#check" do
4
+ before do
5
+ @session.visit('/form')
6
+ end
7
+
8
+ describe "'checked' attribute" do
9
+ it "should be true if checked" do
10
+ @session.check("Terms of Use")
11
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
12
+ end
13
+
14
+ it "should be false if unchecked" do
15
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
16
+ end
17
+ end
18
+
19
+ describe "checking" do
20
+ it "should not change an already checked checkbox" do
21
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
22
+ @session.check('form_pets_dog')
23
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
24
+ end
25
+
26
+ it "should check an unchecked checkbox" do
27
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
28
+ @session.check('form_pets_cat')
29
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
30
+ end
31
+ end
32
+
33
+ describe "unchecking" do
34
+ it "should not change an already unchecked checkbox" do
35
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
36
+ @session.uncheck('form_pets_cat')
37
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
38
+ end
39
+
40
+ it "should uncheck a checked checkbox" do
41
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
42
+ @session.uncheck('form_pets_dog')
43
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
44
+ end
45
+ end
46
+
47
+ it "should check a checkbox by id" do
48
+ @session.check("form_pets_cat")
49
+ @session.click_button('awesome')
50
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
51
+ end
52
+
53
+ it "should check a checkbox by label" do
54
+ @session.check("Cat")
55
+ @session.click_button('awesome')
56
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
57
+ end
58
+
59
+ context "with a locator that doesn't exist" do
60
+ it "should raise an error" do
61
+ running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,26 @@
1
+ shared_examples_for "choose" do
2
+
3
+ describe "#choose" do
4
+ before do
5
+ @session.visit('/form')
6
+ end
7
+
8
+ it "should choose a radio button by id" do
9
+ @session.choose("gender_male")
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['gender'].should == 'male'
12
+ end
13
+
14
+ it "should choose a radio button by label" do
15
+ @session.choose("Both")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['gender'].should == 'both'
18
+ end
19
+
20
+ context "with a locator that doesn't exist" do
21
+ it "should raise an error" do
22
+ running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
23
+ end
24
+ end
25
+ end
26
+ end