capybara_minitest_spec 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rvmrc +1 -1
- data/.travis.yml +1 -1
- data/LICENSE.txt +22 -0
- data/README.md +6 -1
- data/capybara_minitest_spec.gemspec +1 -0
- data/lib/capybara_minitest_spec/version.rb +1 -1
- data/spec/capybara_rspec_matchers.spec.rb +159 -48
- data/spec/helper.rb +1 -33
- metadata +20 -69
- data/.gemtest +0 -0
- data/spec/test_app/test_app.rb +0 -146
- data/spec/test_app/views/buttons.erb +0 -4
- data/spec/test_app/views/fieldsets.erb +0 -29
- data/spec/test_app/views/form.erb +0 -365
- data/spec/test_app/views/frame_one.erb +0 -8
- data/spec/test_app/views/frame_two.erb +0 -8
- data/spec/test_app/views/header_links.erb +0 -7
- data/spec/test_app/views/host_links.erb +0 -12
- data/spec/test_app/views/popup_one.erb +0 -8
- data/spec/test_app/views/popup_two.erb +0 -8
- data/spec/test_app/views/postback.erb +0 -13
- data/spec/test_app/views/tables.erb +0 -122
- data/spec/test_app/views/with_html.erb +0 -74
- data/spec/test_app/views/with_html_entities.erb +0 -1
- data/spec/test_app/views/with_js.erb +0 -48
- data/spec/test_app/views/with_scope.erb +0 -36
- data/spec/test_app/views/with_simple_html.erb +0 -1
- data/spec/test_app/views/within_frames.erb +0 -10
- data/spec/test_app/views/within_popups.erb +0 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2afcd081680564a3493009ed655fe67207cc1319
|
4
|
+
data.tar.gz: 2488130d4e3f241050c48625cbaa17dfc3d3a641
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f72f1f8020db7109a1c92b4defb4699425c1672c12bb80bfce35b964c55b98cd11c579ad60c49914b7f7bdd4af7b74e7335c8a94fe407e4fea839e3bca2704d
|
7
|
+
data.tar.gz: 091ceb109163a9d3da810f2c62857209d3cfcb08ddc6dba25007763253439bf11582cb897dfe8fb502422ba6af7048a72f0838892f078cf161afc38718da4639
|
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm
|
1
|
+
rvm --create ruby-2.0.0-p0@capybara_minispec
|
data/.travis.yml
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jared Ning
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -37,6 +37,9 @@ assert_page_has_content?('<h1>Content</h1>', 'No such Text')
|
|
37
37
|
# fails with 'expected there to be text "No such Text" in "Content"'
|
38
38
|
```
|
39
39
|
|
40
|
+
You can see all the available matchers [here] (https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/matchers.rb#L104).
|
41
|
+
CapybaraMiniTestSpec iterates through those "have_x" methods and creates corresponding MiniTest assertions/expectations.
|
42
|
+
|
40
43
|
## Install
|
41
44
|
|
42
45
|
```ruby
|
@@ -48,7 +51,9 @@ NOTE: If after installing the Capybara gem, Nokogiri isn't installed, it's a kno
|
|
48
51
|
|
49
52
|
## Compatibility
|
50
53
|
|
51
|
-
In theory, this should work with Capybara >= 2.
|
54
|
+
In theory, this should work with Capybara >= 2. The latest version it was tested with was Capybara 2.1.0.
|
55
|
+
|
56
|
+
For Capybara < 2 support, use a version of this gem < 1.0.
|
52
57
|
|
53
58
|
## Testing
|
54
59
|
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/ordinaryzelig/capybara_minitest_spec"
|
11
11
|
s.summary = %q{Capybara + MiniTest::Spec}
|
12
12
|
s.description = %q{Use Capybara matchers with MiniTest. Specifically, it defines MiniTest::Spec expectations like page.must_have_content('content').}
|
13
|
+
s.license = "MIT"
|
13
14
|
|
14
15
|
s.rubyforge_project = "capybara_minitest_spec"
|
15
16
|
|
@@ -1,11 +1,35 @@
|
|
1
|
+
# Copied from 'capybara/spec/rspec/matchers_spec.rb' and changed to use minitest.
|
2
|
+
# https://gist.github.com/4297afa19edd44885248
|
1
3
|
require_relative 'helper'
|
2
4
|
|
3
|
-
#
|
4
|
-
|
5
|
-
|
5
|
+
# Bridge some gaps between RSpec and MiniTest.
|
6
|
+
class Minitest::Test
|
7
|
+
class << self
|
8
|
+
alias_method :context, :describe
|
9
|
+
end
|
10
|
+
alias_method :expect, :proc
|
11
|
+
end
|
6
12
|
|
13
|
+
module MiniTest::Assertions
|
14
|
+
# Yield, rescue, compare exception's message.
|
15
|
+
def assert_fails_with_message(exception_message)
|
16
|
+
yield
|
17
|
+
rescue Exception => exception
|
18
|
+
exception_raised = true
|
19
|
+
assert_match exception_message, exception.message
|
20
|
+
ensure
|
21
|
+
assert exception_raised, 'expected exception to be raised'
|
22
|
+
end
|
23
|
+
Proc.infect_an_assertion :assert_fails_with_message, :must_fail_with_message
|
24
|
+
end
|
25
|
+
|
26
|
+
# There is a capybara/spec/spec_helper, but the following lines seeem to be enough.
|
27
|
+
# Also, capybara/spec/spec_helper requires rspec.
|
28
|
+
require 'capybara/spec/test_app'
|
29
|
+
Capybara.default_selector = :xpath
|
30
|
+
Capybara.app = TestApp
|
7
31
|
|
8
|
-
describe
|
32
|
+
describe Capybara::RSpecMatchers do
|
9
33
|
include Capybara::DSL
|
10
34
|
include Capybara::RSpecMatchers
|
11
35
|
|
@@ -23,7 +47,7 @@ describe CapybaraMiniTestSpec do
|
|
23
47
|
it "fails if has_css? returns false" do
|
24
48
|
expect do
|
25
49
|
"<h1>Text</h1>".must_have_css('h2')
|
26
|
-
end.
|
50
|
+
end.must_fail_with_message(/expected to find css "h2" but there were no matches/)
|
27
51
|
end
|
28
52
|
|
29
53
|
it "passes if matched node count equals expected count" do
|
@@ -32,9 +56,28 @@ describe CapybaraMiniTestSpec do
|
|
32
56
|
|
33
57
|
it "fails if matched node count does not equal expected count" do
|
34
58
|
expect do
|
35
|
-
"<h1>Text</h1>".must_have_css('h1', :
|
36
|
-
end.
|
59
|
+
"<h1>Text</h1>".must_have_css('h1', count: 2)
|
60
|
+
end.must_fail_with_message("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "fails if matched node count is less than expected minimum count" do
|
64
|
+
expect do
|
65
|
+
"<h1>Text</h1>".must_have_css('p', minimum: 1)
|
66
|
+
end.must_fail_with_message("expected to find css \"p\" at least 1 time but there were no matches")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "fails if matched node count is more than expected maximum count" do
|
70
|
+
expect do
|
71
|
+
"<h1>Text</h1><h1>Text</h1><h1>Text</h1>".must_have_css('h1', maximum: 2)
|
72
|
+
end.must_fail_with_message('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "fails if matched node count does not belong to expected range" do
|
76
|
+
expect do
|
77
|
+
"<h1>Text</h1>".must_have_css('h1', between: 2..3)
|
78
|
+
end.must_fail_with_message("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
|
37
79
|
end
|
80
|
+
|
38
81
|
end
|
39
82
|
|
40
83
|
context "with should_not" do
|
@@ -45,7 +88,7 @@ describe CapybaraMiniTestSpec do
|
|
45
88
|
it "fails if has_no_css? returns false" do
|
46
89
|
expect do
|
47
90
|
"<h1>Text</h1>".wont_have_css('h1')
|
48
|
-
end.
|
91
|
+
end.must_fail_with_message(/expected not to find css "h1"/)
|
49
92
|
end
|
50
93
|
|
51
94
|
it "passes if matched node count does not equal expected count" do
|
@@ -55,7 +98,7 @@ describe CapybaraMiniTestSpec do
|
|
55
98
|
it "fails if matched node count equals expected count" do
|
56
99
|
expect do
|
57
100
|
"<h1>Text</h1>".wont_have_css('h1', :count => 1)
|
58
|
-
end.
|
101
|
+
end.must_fail_with_message(/expected not to find css "h1"/)
|
59
102
|
end
|
60
103
|
end
|
61
104
|
end
|
@@ -73,7 +116,7 @@ describe CapybaraMiniTestSpec do
|
|
73
116
|
it "fails if has_css? returns false" do
|
74
117
|
expect do
|
75
118
|
page.must_have_css('h1#doesnotexist')
|
76
|
-
end.
|
119
|
+
end.must_fail_with_message(/expected to find css "h1#doesnotexist" but there were no matches/)
|
77
120
|
end
|
78
121
|
end
|
79
122
|
|
@@ -85,7 +128,7 @@ describe CapybaraMiniTestSpec do
|
|
85
128
|
it "fails if has_no_css? returns false" do
|
86
129
|
expect do
|
87
130
|
page.wont_have_css('h1')
|
88
|
-
end.
|
131
|
+
end.must_fail_with_message(/expected not to find css "h1"/)
|
89
132
|
end
|
90
133
|
end
|
91
134
|
end
|
@@ -105,7 +148,7 @@ describe CapybaraMiniTestSpec do
|
|
105
148
|
it "fails if has_xpath? returns false" do
|
106
149
|
expect do
|
107
150
|
"<h1>Text</h1>".must_have_xpath('//h2')
|
108
|
-
end.
|
151
|
+
end.must_fail_with_message(%r(expected to find xpath "//h2" but there were no matches))
|
109
152
|
end
|
110
153
|
end
|
111
154
|
|
@@ -117,7 +160,7 @@ describe CapybaraMiniTestSpec do
|
|
117
160
|
it "fails if has_no_xpath? returns false" do
|
118
161
|
expect do
|
119
162
|
"<h1>Text</h1>".wont_have_xpath('//h1')
|
120
|
-
end.
|
163
|
+
end.must_fail_with_message(%r(expected not to find xpath "//h1"))
|
121
164
|
end
|
122
165
|
end
|
123
166
|
end
|
@@ -135,7 +178,7 @@ describe CapybaraMiniTestSpec do
|
|
135
178
|
it "fails if has_xpath? returns false" do
|
136
179
|
expect do
|
137
180
|
page.must_have_xpath("//h1[@id='doesnotexist']")
|
138
|
-
end.
|
181
|
+
end.must_fail_with_message(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
139
182
|
end
|
140
183
|
end
|
141
184
|
|
@@ -147,7 +190,7 @@ describe CapybaraMiniTestSpec do
|
|
147
190
|
it "fails if has_no_xpath? returns false" do
|
148
191
|
expect do
|
149
192
|
page.wont_have_xpath('//h1')
|
150
|
-
end.
|
193
|
+
end.must_fail_with_message(%r(expected not to find xpath "//h1"))
|
151
194
|
end
|
152
195
|
end
|
153
196
|
end
|
@@ -156,7 +199,7 @@ describe CapybaraMiniTestSpec do
|
|
156
199
|
describe "have_selector matcher" do
|
157
200
|
it "gives proper description" do
|
158
201
|
matcher = have_selector('//h1')
|
159
|
-
"<h1>Text</h1>"
|
202
|
+
matcher.matches?("<h1>Text</h1>")
|
160
203
|
matcher.description.must_equal "have xpath \"//h1\""
|
161
204
|
end
|
162
205
|
|
@@ -169,7 +212,7 @@ describe CapybaraMiniTestSpec do
|
|
169
212
|
it "fails if has_selector? returns false" do
|
170
213
|
expect do
|
171
214
|
"<h1>Text</h1>".must_have_selector('//h2')
|
172
|
-
end.
|
215
|
+
end.must_fail_with_message(%r(expected to find xpath "//h2" but there were no matches))
|
173
216
|
end
|
174
217
|
end
|
175
218
|
|
@@ -181,7 +224,7 @@ describe CapybaraMiniTestSpec do
|
|
181
224
|
it "fails if has_no_selector? returns false" do
|
182
225
|
expect do
|
183
226
|
"<h1>Text</h1>".wont_have_selector(:css, 'h1')
|
184
|
-
end.
|
227
|
+
end.must_fail_with_message(%r(expected not to find css "h1"))
|
185
228
|
end
|
186
229
|
end
|
187
230
|
end
|
@@ -199,13 +242,13 @@ describe CapybaraMiniTestSpec do
|
|
199
242
|
it "fails if has_selector? returns false" do
|
200
243
|
expect do
|
201
244
|
page.must_have_selector("//h1[@id='doesnotexist']")
|
202
|
-
end.
|
245
|
+
end.must_fail_with_message(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
203
246
|
end
|
204
247
|
|
205
248
|
it "includes text in error message" do
|
206
249
|
expect do
|
207
250
|
page.must_have_selector("//h1", :text => 'wrong text')
|
208
|
-
end.
|
251
|
+
end.must_fail_with_message(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
|
209
252
|
end
|
210
253
|
end
|
211
254
|
|
@@ -217,7 +260,7 @@ describe CapybaraMiniTestSpec do
|
|
217
260
|
it "fails if has_no_selector? returns false" do
|
218
261
|
expect do
|
219
262
|
page.wont_have_selector(:css, 'h1', :text => 'test')
|
220
|
-
end.
|
263
|
+
end.must_fail_with_message(%r(expected not to find css "h1" with text "test"))
|
221
264
|
end
|
222
265
|
end
|
223
266
|
end
|
@@ -225,7 +268,7 @@ describe CapybaraMiniTestSpec do
|
|
225
268
|
|
226
269
|
describe "have_content matcher" do
|
227
270
|
it "gives proper description" do
|
228
|
-
have_content('Text').description.must_equal "
|
271
|
+
have_content('Text').description.must_equal "text \"Text\""
|
229
272
|
end
|
230
273
|
|
231
274
|
context "on a string" do
|
@@ -241,7 +284,7 @@ describe CapybaraMiniTestSpec do
|
|
241
284
|
it "fails if has_content? returns false" do
|
242
285
|
expect do
|
243
286
|
"<h1>Text</h1>".must_have_content('No such Text')
|
244
|
-
end.
|
287
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "Text"/)
|
245
288
|
end
|
246
289
|
end
|
247
290
|
|
@@ -257,7 +300,7 @@ describe CapybaraMiniTestSpec do
|
|
257
300
|
it "fails if has_no_content? returns false" do
|
258
301
|
expect do
|
259
302
|
"<h1>Text</h1>".wont_have_content('Text')
|
260
|
-
end.
|
303
|
+
end.must_fail_with_message(/expected not to find text "Text" in "Text"/)
|
261
304
|
end
|
262
305
|
end
|
263
306
|
end
|
@@ -279,7 +322,7 @@ describe CapybaraMiniTestSpec do
|
|
279
322
|
it "fails if has_content? returns false" do
|
280
323
|
expect do
|
281
324
|
page.must_have_content('No such Text')
|
282
|
-
end.
|
325
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
283
326
|
end
|
284
327
|
|
285
328
|
context "with default selector CSS" do
|
@@ -287,7 +330,7 @@ describe CapybaraMiniTestSpec do
|
|
287
330
|
it "fails if has_content? returns false" do
|
288
331
|
expect do
|
289
332
|
page.must_have_content('No such Text')
|
290
|
-
end.
|
333
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
291
334
|
end
|
292
335
|
after { Capybara.default_selector = :xpath }
|
293
336
|
end
|
@@ -301,7 +344,7 @@ describe CapybaraMiniTestSpec do
|
|
301
344
|
it "fails if has_no_content? returns false" do
|
302
345
|
expect do
|
303
346
|
page.wont_have_content('This is a test')
|
304
|
-
end.
|
347
|
+
end.must_fail_with_message(/expected not to find text "This is a test"/)
|
305
348
|
end
|
306
349
|
end
|
307
350
|
end
|
@@ -309,7 +352,7 @@ describe CapybaraMiniTestSpec do
|
|
309
352
|
|
310
353
|
describe "have_text matcher" do
|
311
354
|
it "gives proper description" do
|
312
|
-
have_text('Text').description.must_equal "
|
355
|
+
have_text('Text').description.must_equal "text \"Text\""
|
313
356
|
end
|
314
357
|
|
315
358
|
context "on a string" do
|
@@ -325,13 +368,37 @@ describe CapybaraMiniTestSpec do
|
|
325
368
|
it "fails if has_text? returns false" do
|
326
369
|
expect do
|
327
370
|
"<h1>Text</h1>".must_have_text('No such Text')
|
328
|
-
end.
|
371
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "Text"/)
|
372
|
+
end
|
373
|
+
|
374
|
+
it "casts Fixnum to string" do
|
375
|
+
expect do
|
376
|
+
"<h1>Text</h1>".must_have_text(3)
|
377
|
+
end.must_fail_with_message(/expected to find text "3" in "Text"/)
|
378
|
+
end
|
379
|
+
|
380
|
+
it "fails if matched text count does not equal to expected count" do
|
381
|
+
expect do
|
382
|
+
"<h1>Text</h1>".must_have_text('Text', count: 2)
|
383
|
+
end.must_fail_with_message(/expected to find text "Text" 2 times in "Text"/)
|
384
|
+
end
|
385
|
+
|
386
|
+
it "fails if matched text count is less than expected minimum count" do
|
387
|
+
expect do
|
388
|
+
"<h1>Text</h1>".must_have_text('Lorem', minimum: 1)
|
389
|
+
end.must_fail_with_message(/expected to find text "Lorem" at least 1 time in "Text"/)
|
390
|
+
end
|
391
|
+
|
392
|
+
it "fails if matched text count is more than expected maximum count" do
|
393
|
+
expect do
|
394
|
+
"<h1>Text TextText</h1>".must_have_text('Text', maximum: 2)
|
395
|
+
end.must_fail_with_message(/expected to find text "Text" at most 2 times in "Text TextText"/)
|
329
396
|
end
|
330
397
|
|
331
|
-
it "
|
398
|
+
it "fails if matched text count does not belong to expected range" do
|
332
399
|
expect do
|
333
|
-
"<h1>Text</h1>".must_have_text(:
|
334
|
-
end.
|
400
|
+
"<h1>Text</h1>".must_have_text('Text', between: 2..3)
|
401
|
+
end.must_fail_with_message(/expected to find text "Text" between 2 and 3 times in "Text"/)
|
335
402
|
end
|
336
403
|
end
|
337
404
|
|
@@ -347,7 +414,7 @@ describe CapybaraMiniTestSpec do
|
|
347
414
|
it "fails if has_no_text? returns false" do
|
348
415
|
expect do
|
349
416
|
"<h1>Text</h1>".wont_have_text('Text')
|
350
|
-
end.
|
417
|
+
end.must_fail_with_message(/expected not to find text "Text" in "Text"/)
|
351
418
|
end
|
352
419
|
end
|
353
420
|
end
|
@@ -366,10 +433,19 @@ describe CapybaraMiniTestSpec do
|
|
366
433
|
page.must_have_text(/test/)
|
367
434
|
end
|
368
435
|
|
436
|
+
it "can check for all text" do
|
437
|
+
page.must_have_text(:all, 'Some of this text is hidden!')
|
438
|
+
end
|
439
|
+
|
440
|
+
it "can check for visible text" do
|
441
|
+
page.must_have_text(:visible, 'Some of this text is')
|
442
|
+
page.wont_have_text(:visible, 'Some of this text is hidden!')
|
443
|
+
end
|
444
|
+
|
369
445
|
it "fails if has_text? returns false" do
|
370
446
|
expect do
|
371
447
|
page.must_have_text('No such Text')
|
372
|
-
end.
|
448
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
373
449
|
end
|
374
450
|
|
375
451
|
context "with default selector CSS" do
|
@@ -377,7 +453,7 @@ describe CapybaraMiniTestSpec do
|
|
377
453
|
it "fails if has_text? returns false" do
|
378
454
|
expect do
|
379
455
|
page.must_have_text('No such Text')
|
380
|
-
end.
|
456
|
+
end.must_fail_with_message(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
381
457
|
end
|
382
458
|
after { Capybara.default_selector = :xpath }
|
383
459
|
end
|
@@ -391,7 +467,7 @@ describe CapybaraMiniTestSpec do
|
|
391
467
|
it "fails if has_no_text? returns false" do
|
392
468
|
expect do
|
393
469
|
page.wont_have_text('This is a test')
|
394
|
-
end.
|
470
|
+
end.must_fail_with_message(/expected not to find text "This is a test"/)
|
395
471
|
end
|
396
472
|
end
|
397
473
|
end
|
@@ -411,7 +487,43 @@ describe CapybaraMiniTestSpec do
|
|
411
487
|
it "fails if there is no such button" do
|
412
488
|
expect do
|
413
489
|
html.must_have_link('No such Link')
|
414
|
-
end.
|
490
|
+
end.must_fail_with_message(/expected to find link "No such Link"/)
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
describe "have_title matcher" do
|
495
|
+
it "gives proper description" do
|
496
|
+
have_title('Just a title').description.must_equal "have title \"Just a title\""
|
497
|
+
end
|
498
|
+
|
499
|
+
context "on a string" do
|
500
|
+
let(:html) { '<title>Just a title</title>' }
|
501
|
+
|
502
|
+
it "passes if there is such a title" do
|
503
|
+
html.must_have_title('Just a title')
|
504
|
+
end
|
505
|
+
|
506
|
+
it "fails if there is no such title" do
|
507
|
+
expect do
|
508
|
+
html.must_have_title('No such title')
|
509
|
+
end.must_fail_with_message(/expected there to be title "No such title"/)
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
context "on a page or node" do
|
514
|
+
before do
|
515
|
+
visit('/with_js')
|
516
|
+
end
|
517
|
+
|
518
|
+
it "passes if there is such a title" do
|
519
|
+
page.must_have_title('with_js')
|
520
|
+
end
|
521
|
+
|
522
|
+
it "fails if there is no such title" do
|
523
|
+
expect do
|
524
|
+
page.must_have_title('No such title')
|
525
|
+
end.must_fail_with_message(/expected there to be title "No such title"/)
|
526
|
+
end
|
415
527
|
end
|
416
528
|
end
|
417
529
|
|
@@ -429,7 +541,7 @@ describe CapybaraMiniTestSpec do
|
|
429
541
|
it "fails if there is no such button" do
|
430
542
|
expect do
|
431
543
|
html.must_have_button('No such Button')
|
432
|
-
end.
|
544
|
+
end.must_fail_with_message(/expected to find button "No such Button"/)
|
433
545
|
end
|
434
546
|
end
|
435
547
|
|
@@ -447,7 +559,7 @@ describe CapybaraMiniTestSpec do
|
|
447
559
|
it "fails if there is no such field" do
|
448
560
|
expect do
|
449
561
|
html.must_have_field('No such Field')
|
450
|
-
end.
|
562
|
+
end.must_fail_with_message(/expected to find field "No such Field"/)
|
451
563
|
end
|
452
564
|
end
|
453
565
|
|
@@ -469,13 +581,13 @@ describe CapybaraMiniTestSpec do
|
|
469
581
|
it "fails if there is such a field but it is not checked" do
|
470
582
|
expect do
|
471
583
|
html.must_have_checked_field('unchecked field')
|
472
|
-
end.
|
584
|
+
end.must_fail_with_message(/expected to find field "unchecked field"/)
|
473
585
|
end
|
474
586
|
|
475
587
|
it "fails if there is no such field" do
|
476
588
|
expect do
|
477
589
|
html.must_have_checked_field('no such field')
|
478
|
-
end.
|
590
|
+
end.must_fail_with_message(/expected to find field "no such field"/)
|
479
591
|
end
|
480
592
|
end
|
481
593
|
|
@@ -483,7 +595,7 @@ describe CapybaraMiniTestSpec do
|
|
483
595
|
it "fails if there is such a field and it is checked" do
|
484
596
|
expect do
|
485
597
|
html.wont_have_checked_field('it is checked')
|
486
|
-
end.
|
598
|
+
end.must_fail_with_message(/expected not to find field "it is checked"/)
|
487
599
|
end
|
488
600
|
|
489
601
|
it "passes if there is such a field but it is not checked" do
|
@@ -514,13 +626,13 @@ describe CapybaraMiniTestSpec do
|
|
514
626
|
it "fails if there is such a field but it is checked" do
|
515
627
|
expect do
|
516
628
|
html.must_have_unchecked_field('it is checked')
|
517
|
-
end.
|
629
|
+
end.must_fail_with_message(/expected to find field "it is checked"/)
|
518
630
|
end
|
519
631
|
|
520
632
|
it "fails if there is no such field" do
|
521
633
|
expect do
|
522
634
|
html.must_have_unchecked_field('no such field')
|
523
|
-
end.
|
635
|
+
end.must_fail_with_message(/expected to find field "no such field"/)
|
524
636
|
end
|
525
637
|
end
|
526
638
|
|
@@ -528,7 +640,7 @@ describe CapybaraMiniTestSpec do
|
|
528
640
|
it "fails if there is such a field and it is not checked" do
|
529
641
|
expect do
|
530
642
|
html.wont_have_unchecked_field('unchecked field')
|
531
|
-
end.
|
643
|
+
end.must_fail_with_message(/expected not to find field "unchecked field"/)
|
532
644
|
end
|
533
645
|
|
534
646
|
it "passes if there is such a field but it is checked" do
|
@@ -555,7 +667,7 @@ describe CapybaraMiniTestSpec do
|
|
555
667
|
it "fails if there is no such select" do
|
556
668
|
expect do
|
557
669
|
html.must_have_select('No such Select box')
|
558
|
-
end.
|
670
|
+
end.must_fail_with_message(/expected to find select box "No such Select box"/)
|
559
671
|
end
|
560
672
|
end
|
561
673
|
|
@@ -573,8 +685,7 @@ describe CapybaraMiniTestSpec do
|
|
573
685
|
it "fails if there is no such select" do
|
574
686
|
expect do
|
575
687
|
html.must_have_table('No such Table')
|
576
|
-
end.
|
688
|
+
end.must_fail_with_message(/expected to find table "No such Table"/)
|
577
689
|
end
|
578
690
|
end
|
579
691
|
end
|
580
|
-
|
data/spec/helper.rb
CHANGED
@@ -1,39 +1,7 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
|
3
3
|
require 'minitest/autorun'
|
4
|
+
require 'minitest/pride'
|
4
5
|
require 'awesome_print'
|
5
6
|
|
6
|
-
require 'capybara/dsl'
|
7
7
|
require 'capybara_minitest_spec'
|
8
|
-
|
9
|
-
# Make all specs a subclass of MiniTest::Spec.
|
10
|
-
MiniTest::Spec.register_spec_type //, MiniTest::Spec
|
11
|
-
|
12
|
-
# Bridge some gaps between RSpec and MiniTest.
|
13
|
-
class MiniTest::Spec
|
14
|
-
|
15
|
-
class << self
|
16
|
-
alias_method :context, :describe
|
17
|
-
end
|
18
|
-
|
19
|
-
alias_method :expect, :proc
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
module MiniTest::Assertions
|
24
|
-
|
25
|
-
# Yield, rescue, compare exception's message.
|
26
|
-
def assert_raises_with_message(exception_message)
|
27
|
-
yield
|
28
|
-
rescue Exception => exception
|
29
|
-
exception_raised = true
|
30
|
-
assert_match exception_message, exception.message
|
31
|
-
ensure
|
32
|
-
assert exception_raised, 'expected exception to be raised'
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
module MiniTest::Expectations
|
38
|
-
infect_an_assertion :assert_raises_with_message, :must_raise_with_message
|
39
|
-
end
|