capybara_minitest_spec 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/HISTORY.md +0 -0
- data/README.md +31 -32
- data/Rakefile +2 -2
- data/capybara_minitest_spec.gemspec +6 -4
- data/lib/capybara_minitest_spec.rb +53 -6
- data/lib/capybara_minitest_spec/test_name.rb +67 -0
- data/lib/capybara_minitest_spec/version.rb +1 -1
- data/spec/capybara_minitest_spec.spec.rb +13 -0
- data/spec/capybara_rspec_matchers.spec.rb +580 -0
- data/spec/helper.rb +39 -0
- data/{test_app → spec/test_app}/test_app.rb +0 -0
- data/{test_app → spec/test_app}/views/buttons.erb +0 -0
- data/{test_app → spec/test_app}/views/fieldsets.erb +0 -0
- data/{test_app → spec/test_app}/views/form.erb +0 -0
- data/{test_app → spec/test_app}/views/frame_one.erb +0 -0
- data/{test_app → spec/test_app}/views/frame_two.erb +0 -0
- data/{test_app → spec/test_app}/views/header_links.erb +0 -0
- data/{test_app → spec/test_app}/views/host_links.erb +0 -0
- data/{test_app → spec/test_app}/views/popup_one.erb +0 -0
- data/{test_app → spec/test_app}/views/popup_two.erb +0 -0
- data/{test_app → spec/test_app}/views/postback.erb +0 -0
- data/{test_app → spec/test_app}/views/tables.erb +0 -0
- data/{test_app → spec/test_app}/views/with_html.erb +0 -0
- data/{test_app → spec/test_app}/views/with_html_entities.erb +0 -0
- data/{test_app → spec/test_app}/views/with_js.erb +0 -0
- data/{test_app → spec/test_app}/views/with_scope.erb +0 -0
- data/{test_app → spec/test_app}/views/with_simple_html.erb +0 -0
- data/{test_app → spec/test_app}/views/within_frames.erb +0 -0
- data/{test_app → spec/test_app}/views/within_popups.erb +0 -0
- data/spec/test_name.spec.rb +47 -0
- metadata +142 -121
- data/lib/capybara_minitest_spec/matcher.rb +0 -126
- data/test/capybara_node_matchers_spec.rb +0 -471
- data/test/custom_matcher_spec.rb +0 -29
- data/test/matcher_spec.rb +0 -45
- data/test/spec_helper.rb +0 -14
- data/test_app/driver.rb +0 -297
- data/test_app/fixtures/capybara.jpg +0 -3
- data/test_app/fixtures/test_file.txt +0 -1
- data/test_app/public/test.js +0 -43
- data/test_app/session.rb +0 -154
- data/test_app/session/all_spec.rb +0 -78
- data/test_app/session/attach_file_spec.rb +0 -73
- data/test_app/session/check_spec.rb +0 -65
- data/test_app/session/choose_spec.rb +0 -26
- data/test_app/session/click_button_spec.rb +0 -304
- data/test_app/session/click_link_or_button_spec.rb +0 -36
- data/test_app/session/click_link_spec.rb +0 -119
- data/test_app/session/current_host_spec.rb +0 -68
- data/test_app/session/current_url_spec.rb +0 -15
- data/test_app/session/fill_in_spec.rb +0 -125
- data/test_app/session/find_button_spec.rb +0 -18
- data/test_app/session/find_by_id_spec.rb +0 -18
- data/test_app/session/find_field_spec.rb +0 -26
- data/test_app/session/find_link_spec.rb +0 -19
- data/test_app/session/find_spec.rb +0 -149
- data/test_app/session/first_spec.rb +0 -105
- data/test_app/session/has_button_spec.rb +0 -32
- data/test_app/session/has_content_spec.rb +0 -106
- data/test_app/session/has_css_spec.rb +0 -243
- data/test_app/session/has_field_spec.rb +0 -192
- data/test_app/session/has_link_spec.rb +0 -37
- data/test_app/session/has_select_spec.rb +0 -129
- data/test_app/session/has_selector_spec.rb +0 -129
- data/test_app/session/has_table_spec.rb +0 -96
- data/test_app/session/has_xpath_spec.rb +0 -123
- data/test_app/session/headers.rb +0 -19
- data/test_app/session/javascript.rb +0 -289
- data/test_app/session/response_code.rb +0 -19
- data/test_app/session/select_spec.rb +0 -113
- data/test_app/session/text_spec.rb +0 -19
- data/test_app/session/uncheck_spec.rb +0 -21
- data/test_app/session/unselect_spec.rb +0 -61
- data/test_app/session/within_spec.rb +0 -178
@@ -1,471 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CapybaraMiniTestSpec do
|
4
|
-
include Capybara::DSL
|
5
|
-
|
6
|
-
describe "have_css matcher" do
|
7
|
-
describe "on a string" do
|
8
|
-
describe "with should" do
|
9
|
-
it "passes if has_css? returns true" do
|
10
|
-
"<h1>Text</h1>".must_have_css('h1')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "fails if has_css? returns false" do
|
14
|
-
proc do
|
15
|
-
"<h1>Text</h1>".must_have_css('h2')
|
16
|
-
end.must_raise(MiniTest::Assertion)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "passes if matched node count equals expected count" do
|
20
|
-
"<h1>Text</h1>".must_have_css('h1', :count => 1)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "fails if matched node count does not equal expected count" do
|
24
|
-
proc do
|
25
|
-
"<h1>Text</h1>".must_have_css('h1', :count => 2)
|
26
|
-
end.must_raise(MiniTest::Assertion)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "with should_not" do
|
31
|
-
it "passes if has_no_css? returns true" do
|
32
|
-
"<h1>Text</h1>".wont_have_css('h2')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "fails if has_no_css? returns false" do
|
36
|
-
proc do
|
37
|
-
"<h1>Text</h1>".wont_have_css('h1')
|
38
|
-
end.must_raise(MiniTest::Assertion)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "passes if matched node count does not equal expected count" do
|
42
|
-
"<h1>Text</h1>".wont_have_css('h1', :count => 2)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "fails if matched node count equals expected count" do
|
46
|
-
proc do
|
47
|
-
"<h1>Text</h1>".wont_have_css('h1', :count => 1)
|
48
|
-
end.must_raise(MiniTest::Assertion)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "on a page or node" do
|
54
|
-
before do
|
55
|
-
visit('/with_html')
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "with should" do
|
59
|
-
it "passes if has_css? returns true" do
|
60
|
-
page.must_have_css('h1')
|
61
|
-
end
|
62
|
-
|
63
|
-
it "fails if has_css? returns false" do
|
64
|
-
proc do
|
65
|
-
page.must_have_css('h1#doesnotexist')
|
66
|
-
end.must_raise(MiniTest::Assertion)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "with should_not" do
|
71
|
-
it "passes if has_no_css? returns true" do
|
72
|
-
page.wont_have_css('h1#doesnotexist')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "fails if has_no_css? returns false" do
|
76
|
-
proc do
|
77
|
-
page.wont_have_css('h1')
|
78
|
-
end.must_raise(MiniTest::Assertion)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "have_xpath matcher" do
|
85
|
-
describe "on a string" do
|
86
|
-
describe "with should" do
|
87
|
-
it "passes if has_css? returns true" do
|
88
|
-
"<h1>Text</h1>".must_have_xpath('//h1')
|
89
|
-
end
|
90
|
-
|
91
|
-
it "fails if has_css? returns false" do
|
92
|
-
proc do
|
93
|
-
"<h1>Text</h1>".must_have_xpath('//h2')
|
94
|
-
end.must_raise(MiniTest::Assertion)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "with should_not" do
|
99
|
-
it "passes if has_no_css? returns true" do
|
100
|
-
"<h1>Text</h1>".wont_have_xpath('//h2')
|
101
|
-
end
|
102
|
-
|
103
|
-
it "fails if has_no_css? returns false" do
|
104
|
-
proc do
|
105
|
-
"<h1>Text</h1>".wont_have_xpath('//h1')
|
106
|
-
end.must_raise(MiniTest::Assertion)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "on a page or node" do
|
112
|
-
before do
|
113
|
-
visit('/with_html')
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "with should" do
|
117
|
-
it "passes if has_css? returns true" do
|
118
|
-
page.must_have_xpath('//h1')
|
119
|
-
end
|
120
|
-
|
121
|
-
it "fails if has_css? returns false" do
|
122
|
-
proc do
|
123
|
-
page.must_have_xpath("//h1[@id='doesnotexist']")
|
124
|
-
end.must_raise(MiniTest::Assertion)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "with should_not" do
|
129
|
-
it "passes if has_no_css? returns true" do
|
130
|
-
page.wont_have_xpath('//h1[@id="doesnotexist"]')
|
131
|
-
end
|
132
|
-
|
133
|
-
it "fails if has_no_css? returns false" do
|
134
|
-
proc do
|
135
|
-
page.wont_have_xpath('//h1')
|
136
|
-
end.must_raise(MiniTest::Assertion)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "have_selector matcher" do
|
143
|
-
describe "on a string" do
|
144
|
-
describe "with should" do
|
145
|
-
it "passes if has_css? returns true" do
|
146
|
-
assert Capybara.string("<h1>Text</h1>").has_selector?('//h1')
|
147
|
-
"<h1>Text</h1>".must_have_selector('//h1')
|
148
|
-
end
|
149
|
-
|
150
|
-
it "fails if has_css? returns false" do
|
151
|
-
proc do
|
152
|
-
"<h1>Text</h1>".must_have_selector('//h2')
|
153
|
-
end.must_raise(MiniTest::Assertion)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "fails with the selector's failure_message if set" do
|
157
|
-
Capybara.add_selector(:monkey) do
|
158
|
-
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
159
|
-
failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
|
160
|
-
end
|
161
|
-
proc do
|
162
|
-
'<h1 id="monkey_paul">Monkey John</h1>'.must_have_selector(:monkey, 14)
|
163
|
-
end.must_raise(MiniTest::Assertion)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "with should_not" do
|
168
|
-
it "passes if has_no_css? returns true" do
|
169
|
-
"<h1>Text</h1>".wont_have_selector(:css, 'h2')
|
170
|
-
end
|
171
|
-
|
172
|
-
it "fails if has_no_css? returns false" do
|
173
|
-
proc do
|
174
|
-
"<h1>Text</h1>".wont_have_selector(:css, 'h1')
|
175
|
-
end.must_raise(MiniTest::Assertion)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe "on a page or node" do
|
181
|
-
before do
|
182
|
-
visit('/with_html')
|
183
|
-
end
|
184
|
-
|
185
|
-
describe "with should" do
|
186
|
-
it "passes if has_css? returns true" do
|
187
|
-
page.must_have_selector('//h1', :text => 'test')
|
188
|
-
end
|
189
|
-
|
190
|
-
it "fails if has_css? returns false" do
|
191
|
-
proc do
|
192
|
-
page.must_have_selector("//h1[@id='doesnotexist']")
|
193
|
-
end.must_raise(MiniTest::Assertion)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "includes text in error message" do
|
197
|
-
proc do
|
198
|
-
page.must_have_selector("//h1", :text => 'wrong text')
|
199
|
-
end.must_raise(MiniTest::Assertion)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "fails with the selector's failure_message if set" do
|
203
|
-
Capybara.add_selector(:monkey) do
|
204
|
-
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
205
|
-
failure_message { |node, selector| node.all(".//*[contains(@id, 'monkey')]").map { |node| node.text }.sort.join(', ') }
|
206
|
-
end
|
207
|
-
proc do
|
208
|
-
page.must_have_selector(:monkey, 14)
|
209
|
-
end.must_raise(MiniTest::Assertion)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe "with should_not" do
|
214
|
-
it "passes if has_no_css? returns true" do
|
215
|
-
page.wont_have_selector(:css, 'h1#doesnotexist')
|
216
|
-
end
|
217
|
-
|
218
|
-
it "fails if has_no_css? returns false" do
|
219
|
-
proc do
|
220
|
-
page.wont_have_selector(:css, 'h1', :text => 'test')
|
221
|
-
end.must_raise(MiniTest::Assertion)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
describe "have_content matcher" do
|
228
|
-
|
229
|
-
describe "on a string" do
|
230
|
-
describe "with should" do
|
231
|
-
it "passes if has_css? returns true" do
|
232
|
-
"<h1>Text</h1>".must_have_content('Text')
|
233
|
-
end
|
234
|
-
|
235
|
-
it "fails if has_css? returns false" do
|
236
|
-
proc do
|
237
|
-
"<h1>Text</h1>".must_have_content('No such Text')
|
238
|
-
end.must_raise(MiniTest::Assertion)
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
describe "with should_not" do
|
243
|
-
it "passes if has_no_css? returns true" do
|
244
|
-
"<h1>Text</h1>".wont_have_content('No such Text')
|
245
|
-
end
|
246
|
-
|
247
|
-
it "fails if has_no_css? returns false" do
|
248
|
-
proc do
|
249
|
-
"<h1>Text</h1>".wont_have_content('Text')
|
250
|
-
end.must_raise(MiniTest::Assertion)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe "on a page or node" do
|
256
|
-
before do
|
257
|
-
visit('/with_html')
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "with should" do
|
261
|
-
it "passes if has_css? returns true" do
|
262
|
-
page.must_have_content('This is a test')
|
263
|
-
end
|
264
|
-
|
265
|
-
it "fails if has_css? returns false" do
|
266
|
-
proc do
|
267
|
-
page.must_have_content('No such Text')
|
268
|
-
end.must_raise(MiniTest::Assertion)
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "with default selector CSS" do
|
272
|
-
before { Capybara.default_selector = :css }
|
273
|
-
it "fails if has_css? returns false" do
|
274
|
-
proc do
|
275
|
-
page.must_have_content('No such Text')
|
276
|
-
end.must_raise(MiniTest::Assertion)
|
277
|
-
end
|
278
|
-
after { Capybara.default_selector = :xpath }
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "with should_not" do
|
283
|
-
it "passes if has_no_css? returns true" do
|
284
|
-
page.wont_have_content('No such Text')
|
285
|
-
end
|
286
|
-
|
287
|
-
it "fails if has_no_css? returns false" do
|
288
|
-
proc do
|
289
|
-
page.wont_have_content('This is a test')
|
290
|
-
end.must_raise(MiniTest::Assertion)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
describe "have_link matcher" do
|
297
|
-
let(:html) { '<a href="#">Just a link</a>' }
|
298
|
-
|
299
|
-
it "passes if there is such a button" do
|
300
|
-
html.must_have_link('Just a link')
|
301
|
-
end
|
302
|
-
|
303
|
-
it "fails if there is no such button" do
|
304
|
-
proc do
|
305
|
-
html.must_have_link('No such Link')
|
306
|
-
end.must_raise(MiniTest::Assertion)
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
describe "have_button matcher" do
|
311
|
-
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
|
312
|
-
|
313
|
-
it "passes if there is such a button" do
|
314
|
-
html.must_have_button('A button')
|
315
|
-
end
|
316
|
-
|
317
|
-
it "fails if there is no such button" do
|
318
|
-
proc do
|
319
|
-
html.must_have_button('No such Button')
|
320
|
-
end.must_raise(MiniTest::Assertion)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "have_field matcher" do
|
325
|
-
let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
|
326
|
-
|
327
|
-
it "passes if there is such a field" do
|
328
|
-
html.must_have_field('Text field')
|
329
|
-
end
|
330
|
-
|
331
|
-
it "fails if there is no such field" do
|
332
|
-
proc do
|
333
|
-
html.must_have_field('No such Field')
|
334
|
-
end.must_raise(MiniTest::Assertion)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
describe "have_checked_field matcher" do
|
339
|
-
let(:html) do
|
340
|
-
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
341
|
-
<label>unchecked field<input type="checkbox"/></label>'
|
342
|
-
end
|
343
|
-
|
344
|
-
describe "with should" do
|
345
|
-
it "passes if there is such a field and it is checked" do
|
346
|
-
html.must_have_checked_field('it is checked')
|
347
|
-
end
|
348
|
-
|
349
|
-
it "fails if there is such a field but it is not checked" do
|
350
|
-
proc do
|
351
|
-
html.must_have_checked_field('unchecked field')
|
352
|
-
end.must_raise(MiniTest::Assertion)
|
353
|
-
end
|
354
|
-
|
355
|
-
it "fails if there is no such field" do
|
356
|
-
proc do
|
357
|
-
html.must_have_checked_field('no such field')
|
358
|
-
end.must_raise(MiniTest::Assertion)
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
describe "with must_not" do
|
363
|
-
it "fails if there is such a field and it is checked" do
|
364
|
-
proc do
|
365
|
-
html.wont_have_checked_field('it is checked')
|
366
|
-
end.must_raise(MiniTest::Assertion)
|
367
|
-
end
|
368
|
-
|
369
|
-
it "passes if there is such a field but it is not checked" do
|
370
|
-
html.wont_have_checked_field('unchecked field')
|
371
|
-
end
|
372
|
-
|
373
|
-
it "passes if there is no such field" do
|
374
|
-
html.wont_have_checked_field('no such field')
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
describe "have_unchecked_field matcher" do
|
380
|
-
let(:html) do
|
381
|
-
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
382
|
-
<label>unchecked field<input type="checkbox"/></label>'
|
383
|
-
end
|
384
|
-
|
385
|
-
describe "with should" do
|
386
|
-
it "passes if there is such a field and it is not checked" do
|
387
|
-
html.must_have_unchecked_field('unchecked field')
|
388
|
-
end
|
389
|
-
|
390
|
-
it "fails if there is such a field but it is checked" do
|
391
|
-
proc do
|
392
|
-
html.must_have_unchecked_field('it is checked')
|
393
|
-
end.must_raise(MiniTest::Assertion)
|
394
|
-
end
|
395
|
-
|
396
|
-
it "fails if there is no such field" do
|
397
|
-
proc do
|
398
|
-
html.must_have_unchecked_field('no such field')
|
399
|
-
end.must_raise(MiniTest::Assertion)
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
describe "with must_not" do
|
404
|
-
it "fails if there is such a field and it is not checked" do
|
405
|
-
proc do
|
406
|
-
html.wont_have_unchecked_field('unchecked field')
|
407
|
-
end.must_raise(MiniTest::Assertion)
|
408
|
-
end
|
409
|
-
|
410
|
-
it "passes if there is such a field but it is checked" do
|
411
|
-
html.wont_have_unchecked_field('it is checked')
|
412
|
-
end
|
413
|
-
|
414
|
-
it "passes if there is no such field" do
|
415
|
-
html.wont_have_unchecked_field('no such field')
|
416
|
-
end
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
describe "have_select matcher" do
|
421
|
-
let(:html) { '<label>Select Box<select></select></label>' }
|
422
|
-
|
423
|
-
it "passes if there is such a select" do
|
424
|
-
html.must_have_select('Select Box')
|
425
|
-
end
|
426
|
-
|
427
|
-
it "fails if there is no such select" do
|
428
|
-
proc do
|
429
|
-
html.must_have_select('No such Select box')
|
430
|
-
end.must_raise(MiniTest::Assertion)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe "have_table matcher" do
|
435
|
-
let(:html) { '<table><caption>Lovely table</caption></table>' }
|
436
|
-
|
437
|
-
it "passes if there is such a select" do
|
438
|
-
html.must_have_table('Lovely table')
|
439
|
-
end
|
440
|
-
|
441
|
-
it "fails if there is no such select" do
|
442
|
-
proc do
|
443
|
-
html.must_have_table('No such Table')
|
444
|
-
end.must_raise(MiniTest::Assertion)
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
describe 'failure message' do
|
449
|
-
it 'for assert shows matcher name and args' do
|
450
|
-
begin
|
451
|
-
'actual'.must_have_css('expected', :count => 1)
|
452
|
-
rescue MiniTest::Assertion => ex
|
453
|
-
exception = ex
|
454
|
-
else
|
455
|
-
flunk 'No exception was raised'
|
456
|
-
end
|
457
|
-
assert_equal 'Matcher failed: has_css?("expected", {:count=>1})', exception.message
|
458
|
-
end
|
459
|
-
|
460
|
-
it 'for refute shows matcher name and args' do
|
461
|
-
begin
|
462
|
-
'<actual/>'.wont_have_css('actual', :count => 1)
|
463
|
-
rescue MiniTest::Assertion => ex
|
464
|
-
exception = ex
|
465
|
-
else
|
466
|
-
flunk 'No exception was raised'
|
467
|
-
end
|
468
|
-
assert_equal 'Matcher should have failed: has_css?("actual", {:count=>1})', exception.message
|
469
|
-
end
|
470
|
-
end
|
471
|
-
end
|