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,243 @@
1
+ shared_examples_for "click_button" do
2
+ describe '#click_button' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ context "with multiple values with the same name" do
8
+ it "should use the latest given value" do
9
+ @session.check('Terms of Use')
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['terms_of_use'].should == '1'
12
+ end
13
+ end
14
+
15
+ context "with value given on a submit button" do
16
+ context "on a form with HTML5 fields" do
17
+ before do
18
+ @session.click_button('html5_submit')
19
+ @results = extract_results(@session)
20
+ end
21
+
22
+ it "should serialise and submit search fields" do
23
+ @results['html5_search'].should == 'what are you looking for'
24
+ end
25
+
26
+ it "should serialise and submit email fields" do
27
+ @results['html5_email'].should == 'person@email.com'
28
+ end
29
+
30
+ it "should serialise and submit url fields" do
31
+ @results['html5_url'].should == 'http://www.example.com'
32
+ end
33
+
34
+ it "should serialise and submit tel fields" do
35
+ @results['html5_tel'].should == '911'
36
+ end
37
+
38
+ it "should serialise and submit color fields" do
39
+ @results['html5_color'].should == '#FFF'
40
+ end
41
+ end
42
+
43
+ context "on an HTML4 form" do
44
+ before do
45
+ @session.click_button('awesome')
46
+ @results = extract_results(@session)
47
+ end
48
+
49
+ it "should serialize and submit text fields" do
50
+ @results['first_name'].should == 'John'
51
+ end
52
+
53
+ it "should escape fields when submitting" do
54
+ @results['phone'].should == '+1 555 7021'
55
+ end
56
+
57
+ it "should serialize and submit password fields" do
58
+ @results['password'].should == 'seeekrit'
59
+ end
60
+
61
+ it "should serialize and submit hidden fields" do
62
+ @results['token'].should == '12345'
63
+ end
64
+
65
+ it "should not serialize fields from other forms" do
66
+ @results['middle_name'].should be_nil
67
+ end
68
+
69
+ it "should submit the button that was clicked, but not other buttons" do
70
+ @results['awesome'].should == 'awesome'
71
+ @results['crappy'].should be_nil
72
+ end
73
+
74
+ it "should serialize radio buttons" do
75
+ @results['gender'].should == 'female'
76
+ end
77
+
78
+ it "should serialize check boxes" do
79
+ @results['pets'].should include('dog', 'hamster')
80
+ @results['pets'].should_not include('cat')
81
+ end
82
+
83
+ it "should serialize text areas" do
84
+ @results['description'].should == 'Descriptive text goes here'
85
+ end
86
+
87
+ it "should serialize select tag with values" do
88
+ @results['locale'].should == 'en'
89
+ end
90
+
91
+ it "should serialize select tag without values" do
92
+ @results['region'].should == 'Norway'
93
+ end
94
+
95
+ it "should serialize first option for select tag with no selection" do
96
+ @results['city'].should == 'London'
97
+ end
98
+
99
+ it "should not serialize a select tag without options" do
100
+ @results['tendency'].should be_nil
101
+ end
102
+ end
103
+ end
104
+
105
+ context "with id given on a submit button" do
106
+ it "should submit the associated form" do
107
+ @session.click_button('awe123')
108
+ extract_results(@session)['first_name'].should == 'John'
109
+ end
110
+
111
+ it "should work with partial matches" do
112
+ @session.click_button('Go')
113
+ @session.body.should include('You landed')
114
+ end
115
+ end
116
+
117
+ context "with alt given on an image button" do
118
+ it "should submit the associated form" do
119
+ @session.click_button('oh hai thar')
120
+ extract_results(@session)['first_name'].should == 'John'
121
+ end
122
+
123
+ it "should work with partial matches" do
124
+ @session.click_button('hai')
125
+ extract_results(@session)['first_name'].should == 'John'
126
+ end
127
+ end
128
+
129
+ context "with value given on an image button" do
130
+ it "should submit the associated form" do
131
+ @session.click_button('okay')
132
+ extract_results(@session)['first_name'].should == 'John'
133
+ end
134
+
135
+ it "should work with partial matches" do
136
+ @session.click_button('kay')
137
+ extract_results(@session)['first_name'].should == 'John'
138
+ end
139
+ end
140
+
141
+ context "with id given on an image button" do
142
+ it "should submit the associated form" do
143
+ @session.click_button('okay556')
144
+ extract_results(@session)['first_name'].should == 'John'
145
+ end
146
+ end
147
+
148
+ context "with text given on a button defined by <button> tag" do
149
+ it "should submit the associated form" do
150
+ @session.click_button('Click me')
151
+ extract_results(@session)['first_name'].should == 'John'
152
+ end
153
+
154
+ it "should work with partial matches" do
155
+ @session.click_button('Click')
156
+ extract_results(@session)['first_name'].should == 'John'
157
+ end
158
+
159
+ it "should prefer exact matches over partial matches" do
160
+ @session.click_button('Just an input')
161
+ extract_results(@session)['button'].should == 'button_second'
162
+ end
163
+ end
164
+
165
+ context "with id given on a button defined by <button> tag" do
166
+ it "should submit the associated form" do
167
+ @session.click_button('click_me_123')
168
+ extract_results(@session)['first_name'].should == 'John'
169
+ end
170
+
171
+ it "should serialize and send GET forms" do
172
+ @session.visit('/form')
173
+ @session.click_button('med')
174
+ @results = extract_results(@session)
175
+ @results['middle_name'].should == 'Darren'
176
+ @results['foo'].should be_nil
177
+ end
178
+ end
179
+
180
+ context "with value given on a button defined by <button> tag" do
181
+ it "should submit the associated form" do
182
+ @session.click_button('click_me')
183
+ extract_results(@session)['first_name'].should == 'John'
184
+ end
185
+
186
+ it "should work with partial matches" do
187
+ @session.click_button('ck_me')
188
+ extract_results(@session)['first_name'].should == 'John'
189
+ end
190
+
191
+ it "should prefer exact matches over partial matches" do
192
+ @session.click_button('Just a button')
193
+ extract_results(@session)['button'].should == 'Just a button'
194
+ end
195
+ end
196
+
197
+ context "with a locator that doesn't exist" do
198
+ it "should raise an error" do
199
+ running do
200
+ @session.click_button('does not exist')
201
+ end.should raise_error(Capybara::ElementNotFound)
202
+ end
203
+ end
204
+
205
+ it "should serialize and send valueless buttons that were clicked" do
206
+ @session.click_button('No Value!')
207
+ @results = extract_results(@session)
208
+ @results['no_value'].should_not be_nil
209
+ end
210
+
211
+ it "should not send image buttons that were not clicked" do
212
+ @session.click_button('Click me!')
213
+ @results = extract_results(@session)
214
+ @results['okay'].should be_nil
215
+ end
216
+
217
+ it "should serialize and send GET forms" do
218
+ @session.visit('/form')
219
+ @session.click_button('med')
220
+ @results = extract_results(@session)
221
+ @results['middle_name'].should == 'Darren'
222
+ @results['foo'].should be_nil
223
+ end
224
+
225
+ it "should follow redirects" do
226
+ @session.click_button('Go FAR')
227
+ @session.current_url.should match(%r{/landed$})
228
+ @session.body.should include('You landed')
229
+ end
230
+
231
+ it "should post pack to the same URL when no action given" do
232
+ @session.visit('/postback')
233
+ @session.click_button('With no action')
234
+ @session.body.should include('Postback')
235
+ end
236
+
237
+ it "should post pack to the same URL when blank action given" do
238
+ @session.visit('/postback')
239
+ @session.click_button('With blank action')
240
+ @session.body.should include('Postback')
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,30 @@
1
+ shared_examples_for "click_link_or_button" do
2
+ describe '#click' do
3
+ it "should click on a link" do
4
+ @session.visit('/with_html')
5
+ @session.click_link_or_button('labore')
6
+ @session.body.should include('Bar')
7
+ end
8
+
9
+ it "should click on a button" do
10
+ @session.visit('/form')
11
+ @session.click_link_or_button('awe123')
12
+ extract_results(@session)['first_name'].should == 'John'
13
+ end
14
+
15
+ it "should be aliased as click for backward compatibility" do
16
+ @session.visit('/form')
17
+ @session.click('awe123')
18
+ extract_results(@session)['first_name'].should == 'John'
19
+ end
20
+
21
+ context "with a locator that doesn't exist" do
22
+ it "should raise an error" do
23
+ @session.visit('/with_html')
24
+ running do
25
+ @session.click_link_or_button('does not exist')
26
+ end.should raise_error(Capybara::ElementNotFound)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,108 @@
1
+ shared_examples_for "click_link" do
2
+ describe '#click_link' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ context "with id given" do
8
+ it "should take user to the linked page" do
9
+ @session.click_link('foo')
10
+ @session.body.should include('Another World')
11
+ end
12
+ end
13
+
14
+ context "with text given" do
15
+ it "should take user to the linked page" do
16
+ @session.click_link('labore')
17
+ @session.body.should include('Bar')
18
+ end
19
+
20
+ it "should accept partial matches" do
21
+ @session.click_link('abo')
22
+ @session.body.should include('Bar')
23
+ end
24
+
25
+ it "should prefer exact matches over partial matches" do
26
+ @session.click_link('A link')
27
+ @session.body.should include('Bar')
28
+ end
29
+ end
30
+
31
+ context "with title given" do
32
+ it "should take user to the linked page" do
33
+ @session.click_link('awesome title')
34
+ @session.body.should include('Bar')
35
+ end
36
+
37
+ it "should accept partial matches" do
38
+ @session.click_link('some tit')
39
+ @session.body.should include('Bar')
40
+ end
41
+
42
+ it "should prefer exact matches over partial matches" do
43
+ @session.click_link('a fine link')
44
+ @session.body.should include('Bar')
45
+ end
46
+ end
47
+
48
+ context "with alternative text given to a contained image" do
49
+ it "should take user to the linked page" do
50
+ @session.click_link('awesome image')
51
+ @session.body.should include('Bar')
52
+ end
53
+
54
+ it "should take user to the linked page" do
55
+ @session.click_link('some imag')
56
+ @session.body.should include('Bar')
57
+ end
58
+
59
+ it "should prefer exact matches over partial matches" do
60
+ @session.click_link('fine image')
61
+ @session.body.should include('Bar')
62
+ end
63
+ end
64
+
65
+ context "with a locator that doesn't exist" do
66
+ it "should raise an error" do
67
+ running do
68
+ @session.click_link('does not exist')
69
+ end.should raise_error(Capybara::ElementNotFound)
70
+ end
71
+ end
72
+
73
+ it "should follow redirects" do
74
+ @session.click_link('Redirect')
75
+ @session.body.should include('You landed')
76
+ end
77
+
78
+ it "should follow redirects" do
79
+ @session.click_link('BackToMyself')
80
+ @session.body.should include('This is a test')
81
+ end
82
+
83
+ it "should do nothing on anchor links" do
84
+ @session.fill_in("test_field", :with => 'blah')
85
+ @session.click_link('Anchor')
86
+ @session.find_field("test_field").value.should == 'blah'
87
+ @session.click_link('Blank Anchor')
88
+ @session.find_field("test_field").value.should == 'blah'
89
+ end
90
+
91
+ it "should do nothing on URL+anchor links for the same page" do
92
+ @session.fill_in("test_field", :with => 'blah')
93
+ @session.click_link('Anchor on same page')
94
+ @session.find_field("test_field").value.should == 'blah'
95
+ end
96
+
97
+ it "should follow link on URL+anchor links for a different page" do
98
+ @session.click_link('Anchor on different page')
99
+ @session.body.should include('Bar')
100
+ end
101
+
102
+ it "raise an error with links with no href" do
103
+ running do
104
+ @session.click_link('No Href')
105
+ end.should raise_error(Capybara::ElementNotFound)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,15 @@
1
+ shared_examples_for "current_url" do
2
+ describe '#current_url' do
3
+ it "should return the current url" do
4
+ @session.visit('/form')
5
+ @session.current_url.should =~ %r(http://[^/]+/form)
6
+ end
7
+ end
8
+
9
+ describe '#current_path' do
10
+ it 'should show the correct location' do
11
+ @session.visit('/foo')
12
+ @session.current_path.should == '/foo'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,119 @@
1
+ shared_examples_for "fill_in" do
2
+ describe "#fill_in" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should fill in a text field by id" do
8
+ @session.fill_in('form_first_name', :with => 'Harry')
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['first_name'].should == 'Harry'
11
+ end
12
+
13
+ it "should fill in a text field by name" do
14
+ @session.fill_in('form[last_name]', :with => 'Green')
15
+ @session.click_button('awesome')
16
+ extract_results(@session)['last_name'].should == 'Green'
17
+ end
18
+
19
+ it "should fill in a text field by label without for" do
20
+ @session.fill_in('Street', :with => 'Avenue Q')
21
+ @session.click_button('awesome')
22
+ extract_results(@session)['street'].should == 'Avenue Q'
23
+ end
24
+
25
+ it "should fill in a url field by label without for" do
26
+ @session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
27
+ @session.click_button('html5_submit')
28
+ extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
29
+ end
30
+
31
+ it "should favour exact label matches over partial matches" do
32
+ @session.fill_in('Name', :with => 'Harry Jones')
33
+ @session.click_button('awesome')
34
+ extract_results(@session)['name'].should == 'Harry Jones'
35
+ end
36
+
37
+ it "should fill in a textarea by id" do
38
+ @session.fill_in('form_description', :with => 'Texty text')
39
+ @session.click_button('awesome')
40
+ extract_results(@session)['description'].should == 'Texty text'
41
+ end
42
+
43
+ it "should fill in a textarea by label" do
44
+ @session.fill_in('Description', :with => 'Texty text')
45
+ @session.click_button('awesome')
46
+ extract_results(@session)['description'].should == 'Texty text'
47
+ end
48
+
49
+ it "should fill in a textarea by name" do
50
+ @session.fill_in('form[description]', :with => 'Texty text')
51
+ @session.click_button('awesome')
52
+ extract_results(@session)['description'].should == 'Texty text'
53
+ end
54
+
55
+ it "should fill in a password field by id" do
56
+ @session.fill_in('form_password', :with => 'supasikrit')
57
+ @session.click_button('awesome')
58
+ extract_results(@session)['password'].should == 'supasikrit'
59
+ end
60
+
61
+ it "should fill in a field with a custom type" do
62
+ @session.fill_in('Schmooo', :with => 'Schmooo is the game')
63
+ @session.click_button('awesome')
64
+ extract_results(@session)['schmooo'].should == 'Schmooo is the game'
65
+ end
66
+
67
+ it "should fill in a field without a type" do
68
+ @session.fill_in('Phone', :with => '+1 555 7022')
69
+ @session.click_button('awesome')
70
+ extract_results(@session)['phone'].should == '+1 555 7022'
71
+ end
72
+
73
+ it "should fill in a password field by name" do
74
+ @session.fill_in('form[password]', :with => 'supasikrit')
75
+ @session.click_button('awesome')
76
+ extract_results(@session)['password'].should == 'supasikrit'
77
+ end
78
+
79
+ it "should fill in a password field by label" do
80
+ @session.fill_in('Password', :with => 'supasikrit')
81
+ @session.click_button('awesome')
82
+ extract_results(@session)['password'].should == 'supasikrit'
83
+ end
84
+
85
+ it "should fill in a password field by name" do
86
+ @session.fill_in('form[password]', :with => 'supasikrit')
87
+ @session.click_button('awesome')
88
+ extract_results(@session)['password'].should == 'supasikrit'
89
+ end
90
+
91
+ it "should prefer exact matches over partial matches" do
92
+ @session.fill_in('Name', :with => 'Ford Prefect')
93
+ @session.click_button('awesome')
94
+ extract_results(@session)['name'].should == 'Ford Prefect'
95
+ end
96
+
97
+ it "should throw an exception if a hash containing 'with' is not provided" do
98
+ lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
99
+ end
100
+
101
+ context "with ignore_hidden_fields" do
102
+ before { Capybara.ignore_hidden_elements = true }
103
+ after { Capybara.ignore_hidden_elements = false }
104
+ it "should not find a hidden field" do
105
+ running do
106
+ @session.fill_in('Super Secret', :with => '777')
107
+ end.should raise_error(Capybara::ElementNotFound)
108
+ end
109
+ end
110
+
111
+ context "with a locator that doesn't exist" do
112
+ it "should raise an error" do
113
+ running do
114
+ @session.fill_in('does not exist', :with => 'Blah blah')
115
+ end.should raise_error(Capybara::ElementNotFound)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples_for "find_button" do
2
+ describe '#find_button' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should find any field" do
8
+ @session.find_button('med')[:id].should == "mediocre"
9
+ @session.find_button('crap321').value.should == "crappy"
10
+ end
11
+
12
+ it "should raise error if the field doesn't exist" do
13
+ running do
14
+ @session.find_button('Does not exist')
15
+ end.should raise_error(Capybara::ElementNotFound)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples_for "find_by_id" do
2
+ describe '#find_by_id' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find any element by id" do
8
+ @session.find_by_id('red').tag_name.should == 'a'
9
+ @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
10
+ end
11
+
12
+ it "should raise error if no element with id is found" do
13
+ running do
14
+ @session.find_by_id('nothing_with_this_id')
15
+ end.should raise_error(Capybara::ElementNotFound)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ shared_examples_for "find_field" do
2
+ describe '#find_field' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should find any field" do
8
+ @session.find_field('Dog').value.should == 'dog'
9
+ @session.find_field('form_description').text.should == 'Descriptive text goes here'
10
+ @session.find_field('Region')[:name].should == 'form[region]'
11
+ end
12
+
13
+ it "should raise error if the field doesn't exist" do
14
+ running do
15
+ @session.find_field('Does not exist')
16
+ end.should raise_error(Capybara::ElementNotFound)
17
+ end
18
+
19
+ it "should be aliased as 'field_labeled' for webrat compatibility" do
20
+ @session.field_labeled('Dog').value.should == 'dog'
21
+ running do
22
+ @session.field_labeled('Does not exist')
23
+ end.should raise_error(Capybara::ElementNotFound)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "find_link" do
2
+
3
+ describe '#find_link' do
4
+ before do
5
+ @session.visit('/with_html')
6
+ end
7
+
8
+ it "should find any field" do
9
+ @session.find_link('foo').text.should == "ullamco"
10
+ @session.find_link('labore')[:href].should == "/with_simple_html"
11
+ end
12
+
13
+ it "should raise error if the field doesn't exist" do
14
+ running do
15
+ @session.find_link('Does not exist')
16
+ end.should raise_error(Capybara::ElementNotFound)
17
+ end
18
+ end
19
+ end