capybara 1.1.4 → 2.0.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 (111) hide show
  1. data/{History.txt → History.md} +138 -0
  2. data/License.txt +22 -0
  3. data/README.md +850 -0
  4. data/lib/capybara/cucumber.rb +2 -5
  5. data/lib/capybara/driver/base.rb +6 -6
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/dsl.rb +13 -124
  8. data/lib/capybara/helpers.rb +33 -0
  9. data/lib/capybara/node/actions.rb +16 -30
  10. data/lib/capybara/node/base.rb +56 -13
  11. data/lib/capybara/node/element.rb +18 -30
  12. data/lib/capybara/node/finders.rb +28 -90
  13. data/lib/capybara/node/matchers.rb +121 -73
  14. data/lib/capybara/node/simple.rb +13 -11
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +27 -39
  17. data/lib/capybara/rack_test/driver.rb +13 -3
  18. data/lib/capybara/rack_test/node.rb +31 -2
  19. data/lib/capybara/result.rb +72 -0
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +33 -63
  22. data/lib/capybara/rspec.rb +7 -4
  23. data/lib/capybara/selector.rb +97 -34
  24. data/lib/capybara/selenium/driver.rb +15 -62
  25. data/lib/capybara/selenium/node.rb +14 -21
  26. data/lib/capybara/server.rb +32 -27
  27. data/lib/capybara/session.rb +90 -50
  28. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  29. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  30. data/lib/capybara/spec/public/jquery.js +9046 -0
  31. data/lib/capybara/spec/public/test.js +3 -0
  32. data/lib/capybara/spec/session/all_spec.rb +61 -59
  33. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
  35. data/lib/capybara/spec/session/body_spec.rb +21 -0
  36. data/lib/capybara/spec/session/check_spec.rb +68 -48
  37. data/lib/capybara/spec/session/choose_spec.rb +32 -18
  38. data/lib/capybara/spec/session/click_button_spec.rb +263 -232
  39. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
  40. data/lib/capybara/spec/session/click_link_spec.rb +96 -96
  41. data/lib/capybara/spec/session/current_url_spec.rb +88 -10
  42. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  43. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  44. data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
  45. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  46. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  47. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  48. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  49. data/lib/capybara/spec/session/find_spec.rb +93 -115
  50. data/lib/capybara/spec/session/first_spec.rb +51 -85
  51. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  52. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  53. data/lib/capybara/spec/session/has_field_spec.rb +170 -144
  54. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  55. data/lib/capybara/spec/session/has_select_spec.rb +161 -109
  56. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  57. data/lib/capybara/spec/session/has_table_spec.rb +22 -88
  58. data/lib/capybara/spec/session/has_text_spec.rb +195 -0
  59. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  60. data/lib/capybara/spec/session/headers.rb +4 -17
  61. data/lib/capybara/spec/session/html_spec.rb +15 -0
  62. data/lib/capybara/spec/session/node_spec.rb +205 -0
  63. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  64. data/lib/capybara/spec/session/response_code.rb +4 -17
  65. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  66. data/lib/capybara/spec/session/screenshot.rb +13 -0
  67. data/lib/capybara/spec/session/select_spec.rb +99 -88
  68. data/lib/capybara/spec/session/source_spec.rb +12 -0
  69. data/lib/capybara/spec/session/text_spec.rb +15 -12
  70. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  71. data/lib/capybara/spec/session/unselect_spec.rb +69 -58
  72. data/lib/capybara/spec/session/visit_spec.rb +74 -0
  73. data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
  74. data/lib/capybara/spec/session/within_spec.rb +118 -131
  75. data/lib/capybara/spec/session/within_window_spec.rb +38 -0
  76. data/lib/capybara/spec/spec_helper.rb +84 -0
  77. data/lib/capybara/spec/test_app.rb +32 -6
  78. data/lib/capybara/spec/views/form.erb +12 -10
  79. data/lib/capybara/spec/views/host_links.erb +2 -2
  80. data/lib/capybara/spec/views/tables.erb +6 -66
  81. data/lib/capybara/spec/views/with_html.erb +9 -4
  82. data/lib/capybara/spec/views/with_js.erb +11 -7
  83. data/lib/capybara/version.rb +1 -1
  84. data/lib/capybara.rb +125 -6
  85. data/spec/basic_node_spec.rb +17 -5
  86. data/spec/capybara_spec.rb +9 -0
  87. data/spec/dsl_spec.rb +31 -17
  88. data/spec/rack_test_spec.rb +157 -0
  89. data/spec/result_spec.rb +51 -0
  90. data/spec/rspec/features_spec.rb +19 -2
  91. data/spec/rspec/matchers_spec.rb +170 -89
  92. data/spec/rspec_spec.rb +1 -3
  93. data/spec/selenium_spec.rb +53 -0
  94. data/spec/server_spec.rb +37 -25
  95. data/spec/spec_helper.rb +1 -30
  96. metadata +39 -31
  97. data/README.rdoc +0 -722
  98. data/lib/capybara/spec/driver.rb +0 -301
  99. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  100. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  101. data/lib/capybara/spec/session/javascript.rb +0 -306
  102. data/lib/capybara/spec/session.rb +0 -154
  103. data/lib/capybara/util/save_and_open_page.rb +0 -44
  104. data/lib/capybara/util/timeout.rb +0 -27
  105. data/spec/driver/rack_test_driver_spec.rb +0 -89
  106. data/spec/driver/selenium_driver_spec.rb +0 -37
  107. data/spec/save_and_open_page_spec.rb +0 -155
  108. data/spec/session/rack_test_session_spec.rb +0 -55
  109. data/spec/session/selenium_session_spec.rb +0 -26
  110. data/spec/string_spec.rb +0 -77
  111. data/spec/timeout_spec.rb +0 -28
@@ -2,15 +2,13 @@ require 'spec_helper'
2
2
  require 'capybara/dsl'
3
3
  require 'capybara/rspec/matchers'
4
4
 
5
- Capybara.app = TestApp
6
-
7
5
  describe Capybara::RSpecMatchers do
8
6
  include Capybara::DSL
9
7
  include Capybara::RSpecMatchers
10
8
 
11
9
  describe "have_css matcher" do
12
10
  it "gives proper description" do
13
- have_css('h1').description.should == "has css \"h1\""
11
+ have_css('h1').description.should == "have css \"h1\""
14
12
  end
15
13
 
16
14
  context "on a string" do
@@ -22,7 +20,7 @@ describe Capybara::RSpecMatchers do
22
20
  it "fails if has_css? returns false" do
23
21
  expect do
24
22
  "<h1>Text</h1>".should have_css('h2')
25
- end.to raise_error(/expected css "h2" to return something/)
23
+ end.to raise_error(/expected to find css "h2" but there were no matches/)
26
24
  end
27
25
 
28
26
  it "passes if matched node count equals expected count" do
@@ -32,7 +30,7 @@ describe Capybara::RSpecMatchers do
32
30
  it "fails if matched node count does not equal expected count" do
33
31
  expect do
34
32
  "<h1>Text</h1>".should have_css('h1', :count => 2)
35
- end.to raise_error(/expected css "h1" to return something/)
33
+ end.to raise_error(/expected css "h1" to be found 2 times/)
36
34
  end
37
35
  end
38
36
 
@@ -44,7 +42,7 @@ describe Capybara::RSpecMatchers do
44
42
  it "fails if has_no_css? returns false" do
45
43
  expect do
46
44
  "<h1>Text</h1>".should_not have_css('h1')
47
- end.to raise_error(/expected css "h1" not to return anything/)
45
+ end.to raise_error(/expected not to find css "h1"/)
48
46
  end
49
47
 
50
48
  it "passes if matched node count does not equal expected count" do
@@ -54,7 +52,7 @@ describe Capybara::RSpecMatchers do
54
52
  it "fails if matched node count equals expected count" do
55
53
  expect do
56
54
  "<h1>Text</h1>".should_not have_css('h1', :count => 1)
57
- end.to raise_error(/expected css "h1" not to return anything/)
55
+ end.to raise_error(/expected not to find css "h1"/)
58
56
  end
59
57
  end
60
58
  end
@@ -72,7 +70,7 @@ describe Capybara::RSpecMatchers do
72
70
  it "fails if has_css? returns false" do
73
71
  expect do
74
72
  page.should have_css('h1#doesnotexist')
75
- end.to raise_error(/expected css "h1#doesnotexist" to return something/)
73
+ end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
76
74
  end
77
75
  end
78
76
 
@@ -84,7 +82,7 @@ describe Capybara::RSpecMatchers do
84
82
  it "fails if has_no_css? returns false" do
85
83
  expect do
86
84
  page.should_not have_css('h1')
87
- end.to raise_error(/expected css "h1" not to return anything/)
85
+ end.to raise_error(/expected not to find css "h1"/)
88
86
  end
89
87
  end
90
88
  end
@@ -92,31 +90,31 @@ describe Capybara::RSpecMatchers do
92
90
 
93
91
  describe "have_xpath matcher" do
94
92
  it "gives proper description" do
95
- have_xpath('//h1').description.should == "has xpath \"\/\/h1\""
93
+ have_xpath('//h1').description.should == "have xpath \"\/\/h1\""
96
94
  end
97
95
 
98
96
  context "on a string" do
99
97
  context "with should" do
100
- it "passes if has_css? returns true" do
98
+ it "passes if has_xpath? returns true" do
101
99
  "<h1>Text</h1>".should have_xpath('//h1')
102
100
  end
103
101
 
104
- it "fails if has_css? returns false" do
102
+ it "fails if has_xpath? returns false" do
105
103
  expect do
106
104
  "<h1>Text</h1>".should have_xpath('//h2')
107
- end.to raise_error(%r(expected xpath "//h2" to return something))
105
+ end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
108
106
  end
109
107
  end
110
108
 
111
109
  context "with should_not" do
112
- it "passes if has_no_css? returns true" do
110
+ it "passes if has_no_xpath? returns true" do
113
111
  "<h1>Text</h1>".should_not have_xpath('//h2')
114
112
  end
115
113
 
116
- it "fails if has_no_css? returns false" do
114
+ it "fails if has_no_xpath? returns false" do
117
115
  expect do
118
116
  "<h1>Text</h1>".should_not have_xpath('//h1')
119
- end.to raise_error(%r(expected xpath "//h1" not to return anything))
117
+ end.to raise_error(%r(expected not to find xpath "//h1"))
120
118
  end
121
119
  end
122
120
  end
@@ -127,26 +125,26 @@ describe Capybara::RSpecMatchers do
127
125
  end
128
126
 
129
127
  context "with should" do
130
- it "passes if has_css? returns true" do
128
+ it "passes if has_xpath? returns true" do
131
129
  page.should have_xpath('//h1')
132
130
  end
133
131
 
134
- it "fails if has_css? returns false" do
132
+ it "fails if has_xpath? returns false" do
135
133
  expect do
136
134
  page.should have_xpath("//h1[@id='doesnotexist']")
137
- end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
135
+ end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
138
136
  end
139
137
  end
140
138
 
141
139
  context "with should_not" do
142
- it "passes if has_no_css? returns true" do
140
+ it "passes if has_no_xpath? returns true" do
143
141
  page.should_not have_xpath('//h1[@id="doesnotexist"]')
144
142
  end
145
143
 
146
- it "fails if has_no_css? returns false" do
144
+ it "fails if has_no_xpath? returns false" do
147
145
  expect do
148
146
  page.should_not have_xpath('//h1')
149
- end.to raise_error(%r(expected xpath "//h1" not to return anything))
147
+ end.to raise_error(%r(expected not to find xpath "//h1"))
150
148
  end
151
149
  end
152
150
  end
@@ -154,41 +152,33 @@ describe Capybara::RSpecMatchers do
154
152
 
155
153
  describe "have_selector matcher" do
156
154
  it "gives proper description" do
157
- have_selector('//h1').description.should == "has xpath \"//h1\""
155
+ matcher = have_selector('//h1')
156
+ "<h1>Text</h1>".should matcher
157
+ matcher.description.should == "have xpath \"//h1\""
158
158
  end
159
159
 
160
160
  context "on a string" do
161
161
  context "with should" do
162
- it "passes if has_css? returns true" do
162
+ it "passes if has_selector? returns true" do
163
163
  "<h1>Text</h1>".should have_selector('//h1')
164
164
  end
165
165
 
166
- it "fails if has_css? returns false" do
166
+ it "fails if has_selector? returns false" do
167
167
  expect do
168
168
  "<h1>Text</h1>".should have_selector('//h2')
169
- end.to raise_error(%r(expected xpath "//h2" to return something))
170
- end
171
-
172
- it "fails with the selector's failure_message if set" do
173
- Capybara.add_selector(:monkey) do
174
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
175
- failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
176
- end
177
- expect do
178
- '<h1 id="monkey_paul">Monkey John</h1>'.should have_selector(:monkey, 14)
179
- end.to raise_error("Monkey John")
169
+ end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
180
170
  end
181
171
  end
182
172
 
183
173
  context "with should_not" do
184
- it "passes if has_no_css? returns true" do
174
+ it "passes if has_no_selector? returns true" do
185
175
  "<h1>Text</h1>".should_not have_selector(:css, 'h2')
186
176
  end
187
177
 
188
- it "fails if has_no_css? returns false" do
178
+ it "fails if has_no_selector? returns false" do
189
179
  expect do
190
180
  "<h1>Text</h1>".should_not have_selector(:css, 'h1')
191
- end.to raise_error(%r(expected css "h1" not to return anything))
181
+ end.to raise_error(%r(expected not to find css "h1"))
192
182
  end
193
183
  end
194
184
  end
@@ -199,30 +189,20 @@ describe Capybara::RSpecMatchers do
199
189
  end
200
190
 
201
191
  context "with should" do
202
- it "passes if has_css? returns true" do
192
+ it "passes if has_selector? returns true" do
203
193
  page.should have_selector('//h1', :text => 'test')
204
194
  end
205
195
 
206
- it "fails if has_css? returns false" do
196
+ it "fails if has_selector? returns false" do
207
197
  expect do
208
198
  page.should have_selector("//h1[@id='doesnotexist']")
209
- end.to raise_error(%r(expected xpath "//h1\[@id='doesnotexist'\]" to return something))
199
+ end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
210
200
  end
211
201
 
212
202
  it "includes text in error message" do
213
203
  expect do
214
204
  page.should have_selector("//h1", :text => 'wrong text')
215
- end.to raise_error(%r(expected xpath "//h1" with text "wrong text" to return something))
216
- end
217
-
218
- it "fails with the selector's failure_message if set" do
219
- Capybara.add_selector(:monkey) do
220
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
221
- failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
222
- end
223
- expect do
224
- page.should have_selector(:monkey, 14)
225
- end.to raise_error("Monkey John, Monkey Paul")
205
+ end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
226
206
  end
227
207
  end
228
208
 
@@ -231,10 +211,10 @@ describe Capybara::RSpecMatchers do
231
211
  page.should_not have_selector(:css, 'h1#doesnotexist')
232
212
  end
233
213
 
234
- it "fails if has_no_css? returns false" do
214
+ it "fails if has_no_selector? returns false" do
235
215
  expect do
236
216
  page.should_not have_selector(:css, 'h1', :text => 'test')
237
- end.to raise_error(%r(expected css "h1" with text "test" not to return anything))
217
+ end.to raise_error(%r(expected not to find css "h1" with text "test"))
238
218
  end
239
219
  end
240
220
  end
@@ -242,31 +222,39 @@ describe Capybara::RSpecMatchers do
242
222
 
243
223
  describe "have_content matcher" do
244
224
  it "gives proper description" do
245
- have_content('Text').description.should == "has content \"Text\""
225
+ have_content('Text').description.should == "have text \"Text\""
246
226
  end
247
227
 
248
228
  context "on a string" do
249
229
  context "with should" do
250
- it "passes if has_css? returns true" do
230
+ it "passes if has_content? returns true" do
251
231
  "<h1>Text</h1>".should have_content('Text')
252
232
  end
253
233
 
254
- it "fails if has_css? returns false" do
234
+ it "passes if has_content? returns true using regexp" do
235
+ "<h1>Text</h1>".should have_content(/ext/)
236
+ end
237
+
238
+ it "fails if has_content? returns false" do
255
239
  expect do
256
240
  "<h1>Text</h1>".should have_content('No such Text')
257
- end.to raise_error(/expected there to be content "No such Text" in "Text"/)
241
+ end.to raise_error(/expected there to be text "No such Text" in "Text"/)
258
242
  end
259
243
  end
260
244
 
261
245
  context "with should_not" do
262
- it "passes if has_no_css? returns true" do
246
+ it "passes if has_no_content? returns true" do
263
247
  "<h1>Text</h1>".should_not have_content('No such Text')
264
248
  end
265
249
 
266
- it "fails if has_no_css? returns false" do
250
+ it "passes because escapes any characters that would have special meaning in a regexp" do
251
+ "<h1>Text</h1>".should_not have_content('.')
252
+ end
253
+
254
+ it "fails if has_no_content? returns false" do
267
255
  expect do
268
256
  "<h1>Text</h1>".should_not have_content('Text')
269
- end.to raise_error(/expected content "Text" not to return anything/)
257
+ end.to raise_error(/expected there not to be text "Text" in "Text"/)
270
258
  end
271
259
  end
272
260
  end
@@ -277,36 +265,130 @@ describe Capybara::RSpecMatchers do
277
265
  end
278
266
 
279
267
  context "with should" do
280
- it "passes if has_css? returns true" do
268
+ it "passes if has_content? returns true" do
281
269
  page.should have_content('This is a test')
282
270
  end
283
271
 
284
- it "fails if has_css? returns false" do
272
+ it "passes if has_content? returns true using regexp" do
273
+ page.should have_content(/test/)
274
+ end
275
+
276
+ it "fails if has_content? returns false" do
285
277
  expect do
286
278
  page.should have_content('No such Text')
287
- end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
279
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
288
280
  end
289
281
 
290
282
  context "with default selector CSS" do
291
283
  before { Capybara.default_selector = :css }
292
- it "fails if has_css? returns false" do
284
+ it "fails if has_content? returns false" do
293
285
  expect do
294
286
  page.should have_content('No such Text')
295
- end.to raise_error(/expected there to be content "No such Text" in "(.*)This is a test(.*)"/)
287
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
296
288
  end
297
289
  after { Capybara.default_selector = :xpath }
298
290
  end
299
291
  end
300
292
 
301
293
  context "with should_not" do
302
- it "passes if has_no_css? returns true" do
294
+ it "passes if has_no_content? returns true" do
303
295
  page.should_not have_content('No such Text')
304
296
  end
305
297
 
306
- it "fails if has_no_css? returns false" do
298
+ it "fails if has_no_content? returns false" do
307
299
  expect do
308
300
  page.should_not have_content('This is a test')
309
- end.to raise_error(/expected content "This is a test" not to return anything/)
301
+ end.to raise_error(/expected there not to be text "This is a test"/)
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ describe "have_text matcher" do
308
+ it "gives proper description" do
309
+ have_text('Text').description.should == "have text \"Text\""
310
+ end
311
+
312
+ context "on a string" do
313
+ context "with should" do
314
+ it "passes if has_text? returns true" do
315
+ "<h1>Text</h1>".should have_text('Text')
316
+ end
317
+
318
+ it "passes if has_text? returns true using regexp" do
319
+ "<h1>Text</h1>".should have_text(/ext/)
320
+ end
321
+
322
+ it "fails if has_text? returns false" do
323
+ expect do
324
+ "<h1>Text</h1>".should have_text('No such Text')
325
+ end.to raise_error(/expected there to be text "No such Text" in "Text"/)
326
+ end
327
+
328
+ it "casts has_text? argument to string" do
329
+ expect do
330
+ "<h1>Text</h1>".should have_text(:cast_me)
331
+ end.to raise_error(/expected there to be text "cast_me" in "Text"/)
332
+ end
333
+ end
334
+
335
+ context "with should_not" do
336
+ it "passes if has_no_text? returns true" do
337
+ "<h1>Text</h1>".should_not have_text('No such Text')
338
+ end
339
+
340
+ it "passes because escapes any characters that would have special meaning in a regexp" do
341
+ "<h1>Text</h1>".should_not have_text('.')
342
+ end
343
+
344
+ it "fails if has_no_text? returns false" do
345
+ expect do
346
+ "<h1>Text</h1>".should_not have_text('Text')
347
+ end.to raise_error(/expected there not to be text "Text" in "Text"/)
348
+ end
349
+ end
350
+ end
351
+
352
+ context "on a page or node" do
353
+ before do
354
+ visit('/with_html')
355
+ end
356
+
357
+ context "with should" do
358
+ it "passes if has_text? returns true" do
359
+ page.should have_text('This is a test')
360
+ end
361
+
362
+ it "passes if has_text? returns true using regexp" do
363
+ page.should have_text(/test/)
364
+ end
365
+
366
+ it "fails if has_text? returns false" do
367
+ expect do
368
+ page.should have_text('No such Text')
369
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
370
+ end
371
+
372
+ context "with default selector CSS" do
373
+ before { Capybara.default_selector = :css }
374
+ it "fails if has_text? returns false" do
375
+ expect do
376
+ page.should have_text('No such Text')
377
+ end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
378
+ end
379
+ after { Capybara.default_selector = :xpath }
380
+ end
381
+ end
382
+
383
+ context "with should_not" do
384
+ it "passes if has_no_text? returns true" do
385
+ page.should_not have_text('No such Text')
386
+ end
387
+
388
+ it "fails if has_no_text? returns false" do
389
+ expect do
390
+ page.should_not have_text('This is a test')
391
+ end.to raise_error(/expected there not to be text "This is a test"/)
310
392
  end
311
393
  end
312
394
  end
@@ -316,7 +398,7 @@ describe Capybara::RSpecMatchers do
316
398
  let(:html) { '<a href="#">Just a link</a>' }
317
399
 
318
400
  it "gives proper description" do
319
- have_link('Just a link').description.should == "has link \"Just a link\""
401
+ have_link('Just a link').description.should == "have link \"Just a link\""
320
402
  end
321
403
 
322
404
  it "passes if there is such a button" do
@@ -326,7 +408,7 @@ describe Capybara::RSpecMatchers do
326
408
  it "fails if there is no such button" do
327
409
  expect do
328
410
  html.should have_link('No such Link')
329
- end.to raise_error(/expected link "No such Link"/)
411
+ end.to raise_error(/expected to find link "No such Link"/)
330
412
  end
331
413
  end
332
414
 
@@ -334,7 +416,7 @@ describe Capybara::RSpecMatchers do
334
416
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
335
417
 
336
418
  it "gives proper description" do
337
- have_button('A button').description.should == "has button \"A button\""
419
+ have_button('A button').description.should == "have button \"A button\""
338
420
  end
339
421
 
340
422
  it "passes if there is such a button" do
@@ -344,7 +426,7 @@ describe Capybara::RSpecMatchers do
344
426
  it "fails if there is no such button" do
345
427
  expect do
346
428
  html.should have_button('No such Button')
347
- end.to raise_error(/expected button "No such Button"/)
429
+ end.to raise_error(/expected to find button "No such Button"/)
348
430
  end
349
431
  end
350
432
 
@@ -352,7 +434,7 @@ describe Capybara::RSpecMatchers do
352
434
  let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
353
435
 
354
436
  it "gives proper description" do
355
- have_field('Text field').description.should == "has field \"Text field\""
437
+ have_field('Text field').description.should == "have field \"Text field\""
356
438
  end
357
439
 
358
440
  it "passes if there is such a field" do
@@ -362,7 +444,7 @@ describe Capybara::RSpecMatchers do
362
444
  it "fails if there is no such field" do
363
445
  expect do
364
446
  html.should have_field('No such Field')
365
- end.to raise_error(/expected field "No such Field"/)
447
+ end.to raise_error(/expected to find field "No such Field"/)
366
448
  end
367
449
  end
368
450
 
@@ -373,7 +455,7 @@ describe Capybara::RSpecMatchers do
373
455
  end
374
456
 
375
457
  it "gives proper description" do
376
- have_checked_field('it is checked').description.should == "has checked_field \"it is checked\""
458
+ have_checked_field('it is checked').description.should == "have field \"it is checked\""
377
459
  end
378
460
 
379
461
  context "with should" do
@@ -384,13 +466,13 @@ describe Capybara::RSpecMatchers do
384
466
  it "fails if there is such a field but it is not checked" do
385
467
  expect do
386
468
  html.should have_checked_field('unchecked field')
387
- end.to raise_error(/expected checked_field "unchecked field"/)
469
+ end.to raise_error(/expected to find field "unchecked field"/)
388
470
  end
389
471
 
390
472
  it "fails if there is no such field" do
391
473
  expect do
392
474
  html.should have_checked_field('no such field')
393
- end.to raise_error(/expected checked_field "no such field"/)
475
+ end.to raise_error(/expected to find field "no such field"/)
394
476
  end
395
477
  end
396
478
 
@@ -398,7 +480,7 @@ describe Capybara::RSpecMatchers do
398
480
  it "fails if there is such a field and it is checked" do
399
481
  expect do
400
482
  html.should_not have_checked_field('it is checked')
401
- end.to raise_error(/expected checked_field "it is checked" not to return anything/)
483
+ end.to raise_error(/expected not to find field "it is checked"/)
402
484
  end
403
485
 
404
486
  it "passes if there is such a field but it is not checked" do
@@ -418,7 +500,7 @@ describe Capybara::RSpecMatchers do
418
500
  end
419
501
 
420
502
  it "gives proper description" do
421
- have_unchecked_field('unchecked field').description.should == "has unchecked_field \"unchecked field\""
503
+ have_unchecked_field('unchecked field').description.should == "have field \"unchecked field\""
422
504
  end
423
505
 
424
506
  context "with should" do
@@ -429,13 +511,13 @@ describe Capybara::RSpecMatchers do
429
511
  it "fails if there is such a field but it is checked" do
430
512
  expect do
431
513
  html.should have_unchecked_field('it is checked')
432
- end.to raise_error(/expected unchecked_field "it is checked"/)
514
+ end.to raise_error(/expected to find field "it is checked"/)
433
515
  end
434
516
 
435
517
  it "fails if there is no such field" do
436
518
  expect do
437
519
  html.should have_unchecked_field('no such field')
438
- end.to raise_error(/expected unchecked_field "no such field"/)
520
+ end.to raise_error(/expected to find field "no such field"/)
439
521
  end
440
522
  end
441
523
 
@@ -443,7 +525,7 @@ describe Capybara::RSpecMatchers do
443
525
  it "fails if there is such a field and it is not checked" do
444
526
  expect do
445
527
  html.should_not have_unchecked_field('unchecked field')
446
- end.to raise_error(/expected unchecked_field "unchecked field" not to return anything/)
528
+ end.to raise_error(/expected not to find field "unchecked field"/)
447
529
  end
448
530
 
449
531
  it "passes if there is such a field but it is checked" do
@@ -460,7 +542,7 @@ describe Capybara::RSpecMatchers do
460
542
  let(:html) { '<label>Select Box<select></select></label>' }
461
543
 
462
544
  it "gives proper description" do
463
- have_select('Select Box').description.should == "has select \"Select Box\""
545
+ have_select('Select Box').description.should == "have select box \"Select Box\""
464
546
  end
465
547
 
466
548
  it "passes if there is such a select" do
@@ -470,7 +552,7 @@ describe Capybara::RSpecMatchers do
470
552
  it "fails if there is no such select" do
471
553
  expect do
472
554
  html.should have_select('No such Select box')
473
- end.to raise_error(/expected select "No such Select box"/)
555
+ end.to raise_error(/expected to find select box "No such Select box"/)
474
556
  end
475
557
  end
476
558
 
@@ -478,7 +560,7 @@ describe Capybara::RSpecMatchers do
478
560
  let(:html) { '<table><caption>Lovely table</caption></table>' }
479
561
 
480
562
  it "gives proper description" do
481
- have_table('Lovely table').description.should == "has table \"Lovely table\""
563
+ have_table('Lovely table').description.should == "have table \"Lovely table\""
482
564
  end
483
565
 
484
566
  it "passes if there is such a select" do
@@ -488,8 +570,7 @@ describe Capybara::RSpecMatchers do
488
570
  it "fails if there is no such select" do
489
571
  expect do
490
572
  html.should have_table('No such Table')
491
- end.to raise_error(/expected table "No such Table"/)
573
+ end.to raise_error(/expected to find table "No such Table"/)
492
574
  end
493
575
  end
494
576
  end
495
-
data/spec/rspec_spec.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- Capybara.app = TestApp
4
-
5
- describe 'capybara/rspec', :type => :request do
3
+ describe 'capybara/rspec', :type => :feature do
6
4
  it "should include Capybara in rspec" do
7
5
  visit('/foo')
8
6
  page.body.should include('Another World')
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module TestSessions
4
+ Selenium = Capybara::Session.new(:selenium, TestApp)
5
+ end
6
+
7
+ Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :skip => [
8
+ :response_headers,
9
+ :status_code,
10
+ :source,
11
+ :trigger
12
+ ]
13
+
14
+ describe Capybara::Session do
15
+ context 'with selenium driver' do
16
+ before do
17
+ @session = TestSessions::Selenium
18
+ end
19
+
20
+ describe '#driver' do
21
+ it "should be a selenium driver" do
22
+ @session.driver.should be_an_instance_of(Capybara::Selenium::Driver)
23
+ end
24
+ end
25
+
26
+ describe '#mode' do
27
+ it "should remember the mode" do
28
+ @session.mode.should == :selenium
29
+ end
30
+ end
31
+
32
+ describe "exit codes" do
33
+ before do
34
+ @current_dir = Dir.getwd
35
+ Dir.chdir(File.join(File.dirname(__FILE__), '..'))
36
+ end
37
+
38
+ after do
39
+ Dir.chdir(@current_dir)
40
+ end
41
+
42
+ it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
43
+ `rspec spec/fixtures/selenium_driver_rspec_failure.rb`
44
+ $?.exitstatus.should be 1
45
+ end
46
+
47
+ it "should have return code 0 when running selenium_driver_rspec_success.rb" do
48
+ `rspec spec/fixtures/selenium_driver_rspec_success.rb`
49
+ $?.exitstatus.should be 0
50
+ end
51
+ end
52
+ end
53
+ end