capybara_minitest_spec 0.1.3 → 0.2.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.
- data/capybara_minitest_spec.gemspec +1 -1
- data/lib/capybara_minitest_spec/matcher.rb +125 -0
- data/lib/capybara_minitest_spec/version.rb +2 -2
- data/lib/capybara_minitest_spec.rb +8 -54
- data/test/{matchers_spec.rb → capybara_node_matchers_spec.rb} +46 -35
- data/test/matcher_spec.rb +45 -0
- data/test/spec_helper.rb +3 -8
- metadata +7 -4
@@ -4,7 +4,7 @@ require "capybara_minitest_spec/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "capybara_minitest_spec"
|
7
|
-
s.version =
|
7
|
+
s.version = CapybaraMiniTestSpec::VERSION
|
8
8
|
s.authors = ["Jared Ning"]
|
9
9
|
s.email = ["jared@redningja.com"]
|
10
10
|
s.homepage = ""
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module CapybaraMiniTestSpec
|
2
|
+
class Matcher
|
3
|
+
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(node_matcher_name)
|
7
|
+
@name = Name.new(node_matcher_name, true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_expectations
|
11
|
+
# Define positive expectations.
|
12
|
+
define_expectation
|
13
|
+
# Define negative expectations.
|
14
|
+
@name.negate!
|
15
|
+
define_expectation
|
16
|
+
end
|
17
|
+
|
18
|
+
def undefine_assertions
|
19
|
+
undefine_assertion
|
20
|
+
@name.negate!
|
21
|
+
undefine_assertion
|
22
|
+
end
|
23
|
+
|
24
|
+
# Send page the matcher name with args.
|
25
|
+
# E.g. page.has_css?(*args)
|
26
|
+
def test(page, *args)
|
27
|
+
wrap(page).send(name.original, *args)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Compose failure message.
|
31
|
+
# E.g. Matcher failed: has_css?("expected", {:count => 1})
|
32
|
+
def self.failure_message(assertion_method, matcher_name, *args)
|
33
|
+
if assertion_method == 'assert'
|
34
|
+
message = "Matcher failed: "
|
35
|
+
else
|
36
|
+
message = 'Matcher should have failed: '
|
37
|
+
end
|
38
|
+
message += "#{matcher_name}(#{args.map(&:inspect).join(', ')})"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def define_expectation
|
44
|
+
define_assertion
|
45
|
+
infect_assertion
|
46
|
+
end
|
47
|
+
|
48
|
+
# Define an assertion with the matcher name in MiniTest::Assertions.
|
49
|
+
# For example, if the matcher name is has_css?,
|
50
|
+
# the assertion would be called assert_page_has_css.
|
51
|
+
def define_assertion
|
52
|
+
# scope self to be available in the method definition.
|
53
|
+
matcher = self
|
54
|
+
assertion_method = name.positive? ? 'assert' : 'refute'
|
55
|
+
MiniTest::Assertions.send :define_method, name.assertion do |page, *args|
|
56
|
+
message = matcher.class.failure_message(assertion_method, matcher.name.original, *args)
|
57
|
+
send(assertion_method, matcher.test(page, *args), message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def undefine_assertion
|
62
|
+
MiniTest::Assertions.send :undef_method, @name.assertion
|
63
|
+
end
|
64
|
+
|
65
|
+
def infect_assertion
|
66
|
+
MiniTest::Expectations.infect_an_assertion @name.assertion, @name.expectation, true
|
67
|
+
end
|
68
|
+
|
69
|
+
# Turn a string into a Capybara node if it's not already.
|
70
|
+
# Copied from Capybara::RSpecMatchers::HaveMatcher.
|
71
|
+
def wrap(actual)
|
72
|
+
if actual.respond_to?("has_selector?")
|
73
|
+
actual
|
74
|
+
else
|
75
|
+
Capybara.string(actual.to_s)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Represents the a matcher name.
|
80
|
+
# Returns different forms of the name depending on whether it is in a positive or negative state.
|
81
|
+
class Name
|
82
|
+
|
83
|
+
attr_reader :original
|
84
|
+
|
85
|
+
def initialize(name, positive)
|
86
|
+
@original = name.to_s
|
87
|
+
@positive = positive
|
88
|
+
end
|
89
|
+
|
90
|
+
def positive?
|
91
|
+
!!@positive
|
92
|
+
end
|
93
|
+
|
94
|
+
def negate!
|
95
|
+
@positive = !positive?
|
96
|
+
end
|
97
|
+
|
98
|
+
def without_question_mark
|
99
|
+
@original.to_s.sub /\?$/, ''
|
100
|
+
end
|
101
|
+
|
102
|
+
def have
|
103
|
+
without_question_mark.sub /has_/, 'have_'
|
104
|
+
end
|
105
|
+
|
106
|
+
def assertion
|
107
|
+
if positive?
|
108
|
+
"assert_page_#{without_question_mark}"
|
109
|
+
else
|
110
|
+
"refute_page_#{without_question_mark}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def expectation
|
115
|
+
if positive?
|
116
|
+
"must_#{have}"
|
117
|
+
else
|
118
|
+
"wont_#{have}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.
|
1
|
+
module CapybaraMiniTestSpec
|
2
|
+
VERSION = '0.2.0'
|
3
3
|
end
|
@@ -1,58 +1,12 @@
|
|
1
1
|
require 'minitest/spec'
|
2
|
+
require 'capybara'
|
3
|
+
require "capybara_minitest_spec/matcher"
|
2
4
|
require "capybara_minitest_spec/version"
|
3
5
|
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
without_question_mark = matcher_name.to_s.sub /\?$/, ''
|
11
|
-
have = without_question_mark.sub /has_/, 'have_'
|
12
|
-
|
13
|
-
# Define positive assertion.
|
14
|
-
positive_assertion_name = :"assert_page_#{without_question_mark}"
|
15
|
-
define_method positive_assertion_name do |page, *args|
|
16
|
-
assert wrap(page).send(matcher_name, *args), positive_failure_message(matcher_name, *args)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Infect positive assertion.
|
20
|
-
positive_expectation_name = :"must_#{have}"
|
21
|
-
infect_an_assertion positive_assertion_name, positive_expectation_name, true
|
22
|
-
|
23
|
-
# Define negative assertion.
|
24
|
-
negative_assertion_name = :"refute_page_#{without_question_mark}"
|
25
|
-
define_method negative_assertion_name do |page, *args|
|
26
|
-
refute wrap(page).send(matcher_name, *args), negative_failure_message(matcher_name, *args)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Infect negative assertions.
|
30
|
-
negative_expectation_name = :"wont_#{have}"
|
31
|
-
infect_an_assertion negative_assertion_name, negative_expectation_name, true
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# Copied from Capybara::RSpecMatchers::HaveMatcher.
|
38
|
-
def wrap(actual)
|
39
|
-
if actual.respond_to?("has_selector?")
|
40
|
-
actual
|
41
|
-
else
|
42
|
-
Capybara.string(actual.to_s)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def base_failure_message(matcher_name, *args)
|
47
|
-
"#{matcher_name}(#{args.map(&:inspect).join(', ')})"
|
48
|
-
end
|
49
|
-
|
50
|
-
def positive_failure_message(matcher_name, *args)
|
51
|
-
"Matcher failed: #{base_failure_message(matcher_name, *args)}"
|
52
|
-
end
|
53
|
-
|
54
|
-
def negative_failure_message(matcher_name, *args)
|
55
|
-
"Matcher should have failed: #{base_failure_message(matcher_name, *args)}"
|
56
|
-
end
|
57
|
-
|
6
|
+
# For each Capybara node matcher,
|
7
|
+
# define positive and negative MiniTest::Unit assertions and
|
8
|
+
# infect it both assertions to create MiniTest::Spec expectations.
|
9
|
+
Capybara::Node::Matchers.public_instance_methods.each do |matcher_name|
|
10
|
+
matcher = CapybaraMiniTestSpec::Matcher.new(matcher_name)
|
11
|
+
matcher.define_expectations
|
58
12
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe CapybaraMiniTestSpec do
|
4
4
|
include Capybara::DSL
|
5
5
|
|
6
6
|
describe "have_css matcher" do
|
@@ -13,7 +13,7 @@ describe CapybaraMinitestSpec do
|
|
13
13
|
it "fails if has_css? returns false" do
|
14
14
|
proc do
|
15
15
|
"<h1>Text</h1>".must_have_css('h2')
|
16
|
-
end.must_raise(
|
16
|
+
end.must_raise(MiniTest::Assertion)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "passes if matched node count equals expected count" do
|
@@ -23,7 +23,7 @@ describe CapybaraMinitestSpec do
|
|
23
23
|
it "fails if matched node count does not equal expected count" do
|
24
24
|
proc do
|
25
25
|
"<h1>Text</h1>".must_have_css('h1', :count => 2)
|
26
|
-
end.must_raise(
|
26
|
+
end.must_raise(MiniTest::Assertion)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -35,7 +35,7 @@ describe CapybaraMinitestSpec do
|
|
35
35
|
it "fails if has_no_css? returns false" do
|
36
36
|
proc do
|
37
37
|
"<h1>Text</h1>".wont_have_css('h1')
|
38
|
-
end.must_raise(
|
38
|
+
end.must_raise(MiniTest::Assertion)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "passes if matched node count does not equal expected count" do
|
@@ -45,7 +45,7 @@ describe CapybaraMinitestSpec do
|
|
45
45
|
it "fails if matched node count equals expected count" do
|
46
46
|
proc do
|
47
47
|
"<h1>Text</h1>".wont_have_css('h1', :count => 1)
|
48
|
-
end.must_raise(
|
48
|
+
end.must_raise(MiniTest::Assertion)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -63,7 +63,7 @@ describe CapybaraMinitestSpec do
|
|
63
63
|
it "fails if has_css? returns false" do
|
64
64
|
proc do
|
65
65
|
page.must_have_css('h1#doesnotexist')
|
66
|
-
end.must_raise(
|
66
|
+
end.must_raise(MiniTest::Assertion)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -75,7 +75,7 @@ describe CapybaraMinitestSpec do
|
|
75
75
|
it "fails if has_no_css? returns false" do
|
76
76
|
proc do
|
77
77
|
page.wont_have_css('h1')
|
78
|
-
end.must_raise(
|
78
|
+
end.must_raise(MiniTest::Assertion)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -91,7 +91,7 @@ describe CapybaraMinitestSpec do
|
|
91
91
|
it "fails if has_css? returns false" do
|
92
92
|
proc do
|
93
93
|
"<h1>Text</h1>".must_have_xpath('//h2')
|
94
|
-
end.must_raise(
|
94
|
+
end.must_raise(MiniTest::Assertion)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -103,7 +103,7 @@ describe CapybaraMinitestSpec do
|
|
103
103
|
it "fails if has_no_css? returns false" do
|
104
104
|
proc do
|
105
105
|
"<h1>Text</h1>".wont_have_xpath('//h1')
|
106
|
-
end.must_raise(
|
106
|
+
end.must_raise(MiniTest::Assertion)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -121,7 +121,7 @@ describe CapybaraMinitestSpec do
|
|
121
121
|
it "fails if has_css? returns false" do
|
122
122
|
proc do
|
123
123
|
page.must_have_xpath("//h1[@id='doesnotexist']")
|
124
|
-
end.must_raise(
|
124
|
+
end.must_raise(MiniTest::Assertion)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -133,7 +133,7 @@ describe CapybaraMinitestSpec do
|
|
133
133
|
it "fails if has_no_css? returns false" do
|
134
134
|
proc do
|
135
135
|
page.wont_have_xpath('//h1')
|
136
|
-
end.must_raise(
|
136
|
+
end.must_raise(MiniTest::Assertion)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -150,7 +150,7 @@ describe CapybaraMinitestSpec do
|
|
150
150
|
it "fails if has_css? returns false" do
|
151
151
|
proc do
|
152
152
|
"<h1>Text</h1>".must_have_selector('//h2')
|
153
|
-
end.must_raise(
|
153
|
+
end.must_raise(MiniTest::Assertion)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "fails with the selector's failure_message if set" do
|
@@ -160,7 +160,7 @@ describe CapybaraMinitestSpec do
|
|
160
160
|
end
|
161
161
|
proc do
|
162
162
|
'<h1 id="monkey_paul">Monkey John</h1>'.must_have_selector(:monkey, 14)
|
163
|
-
end.must_raise(
|
163
|
+
end.must_raise(MiniTest::Assertion)
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -172,7 +172,7 @@ describe CapybaraMinitestSpec do
|
|
172
172
|
it "fails if has_no_css? returns false" do
|
173
173
|
proc do
|
174
174
|
"<h1>Text</h1>".wont_have_selector(:css, 'h1')
|
175
|
-
end.must_raise(
|
175
|
+
end.must_raise(MiniTest::Assertion)
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
@@ -190,13 +190,13 @@ describe CapybaraMinitestSpec do
|
|
190
190
|
it "fails if has_css? returns false" do
|
191
191
|
proc do
|
192
192
|
page.must_have_selector("//h1[@id='doesnotexist']")
|
193
|
-
end.must_raise(
|
193
|
+
end.must_raise(MiniTest::Assertion)
|
194
194
|
end
|
195
195
|
|
196
196
|
it "includes text in error message" do
|
197
197
|
proc do
|
198
198
|
page.must_have_selector("//h1", :text => 'wrong text')
|
199
|
-
end.must_raise(
|
199
|
+
end.must_raise(MiniTest::Assertion)
|
200
200
|
end
|
201
201
|
|
202
202
|
it "fails with the selector's failure_message if set" do
|
@@ -206,7 +206,7 @@ describe CapybaraMinitestSpec do
|
|
206
206
|
end
|
207
207
|
proc do
|
208
208
|
page.must_have_selector(:monkey, 14)
|
209
|
-
end.must_raise(
|
209
|
+
end.must_raise(MiniTest::Assertion)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -218,7 +218,7 @@ describe CapybaraMinitestSpec do
|
|
218
218
|
it "fails if has_no_css? returns false" do
|
219
219
|
proc do
|
220
220
|
page.wont_have_selector(:css, 'h1', :text => 'test')
|
221
|
-
end.must_raise(
|
221
|
+
end.must_raise(MiniTest::Assertion)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
end
|
@@ -235,7 +235,7 @@ describe CapybaraMinitestSpec do
|
|
235
235
|
it "fails if has_css? returns false" do
|
236
236
|
proc do
|
237
237
|
"<h1>Text</h1>".must_have_content('No such Text')
|
238
|
-
end.must_raise(
|
238
|
+
end.must_raise(MiniTest::Assertion)
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
@@ -247,7 +247,7 @@ describe CapybaraMinitestSpec do
|
|
247
247
|
it "fails if has_no_css? returns false" do
|
248
248
|
proc do
|
249
249
|
"<h1>Text</h1>".wont_have_content('Text')
|
250
|
-
end.must_raise(
|
250
|
+
end.must_raise(MiniTest::Assertion)
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
@@ -265,7 +265,7 @@ describe CapybaraMinitestSpec do
|
|
265
265
|
it "fails if has_css? returns false" do
|
266
266
|
proc do
|
267
267
|
page.must_have_content('No such Text')
|
268
|
-
end.must_raise(
|
268
|
+
end.must_raise(MiniTest::Assertion)
|
269
269
|
end
|
270
270
|
|
271
271
|
describe "with default selector CSS" do
|
@@ -273,7 +273,7 @@ describe CapybaraMinitestSpec do
|
|
273
273
|
it "fails if has_css? returns false" do
|
274
274
|
proc do
|
275
275
|
page.must_have_content('No such Text')
|
276
|
-
end.must_raise(
|
276
|
+
end.must_raise(MiniTest::Assertion)
|
277
277
|
end
|
278
278
|
after { Capybara.default_selector = :xpath }
|
279
279
|
end
|
@@ -287,7 +287,7 @@ describe CapybaraMinitestSpec do
|
|
287
287
|
it "fails if has_no_css? returns false" do
|
288
288
|
proc do
|
289
289
|
page.wont_have_content('This is a test')
|
290
|
-
end.must_raise(
|
290
|
+
end.must_raise(MiniTest::Assertion)
|
291
291
|
end
|
292
292
|
end
|
293
293
|
end
|
@@ -303,7 +303,7 @@ describe CapybaraMinitestSpec do
|
|
303
303
|
it "fails if there is no such button" do
|
304
304
|
proc do
|
305
305
|
html.must_have_link('No such Link')
|
306
|
-
end.must_raise(
|
306
|
+
end.must_raise(MiniTest::Assertion)
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -317,7 +317,7 @@ describe CapybaraMinitestSpec do
|
|
317
317
|
it "fails if there is no such button" do
|
318
318
|
proc do
|
319
319
|
html.must_have_button('No such Button')
|
320
|
-
end.must_raise(
|
320
|
+
end.must_raise(MiniTest::Assertion)
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
@@ -331,7 +331,7 @@ describe CapybaraMinitestSpec do
|
|
331
331
|
it "fails if there is no such field" do
|
332
332
|
proc do
|
333
333
|
html.must_have_field('No such Field')
|
334
|
-
end.must_raise(
|
334
|
+
end.must_raise(MiniTest::Assertion)
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
@@ -349,13 +349,13 @@ describe CapybaraMinitestSpec do
|
|
349
349
|
it "fails if there is such a field but it is not checked" do
|
350
350
|
proc do
|
351
351
|
html.must_have_checked_field('unchecked field')
|
352
|
-
end.must_raise(
|
352
|
+
end.must_raise(MiniTest::Assertion)
|
353
353
|
end
|
354
354
|
|
355
355
|
it "fails if there is no such field" do
|
356
356
|
proc do
|
357
357
|
html.must_have_checked_field('no such field')
|
358
|
-
end.must_raise(
|
358
|
+
end.must_raise(MiniTest::Assertion)
|
359
359
|
end
|
360
360
|
end
|
361
361
|
|
@@ -363,7 +363,7 @@ describe CapybaraMinitestSpec do
|
|
363
363
|
it "fails if there is such a field and it is checked" do
|
364
364
|
proc do
|
365
365
|
html.wont_have_checked_field('it is checked')
|
366
|
-
end.must_raise(
|
366
|
+
end.must_raise(MiniTest::Assertion)
|
367
367
|
end
|
368
368
|
|
369
369
|
it "passes if there is such a field but it is not checked" do
|
@@ -390,13 +390,13 @@ describe CapybaraMinitestSpec do
|
|
390
390
|
it "fails if there is such a field but it is checked" do
|
391
391
|
proc do
|
392
392
|
html.must_have_unchecked_field('it is checked')
|
393
|
-
end.must_raise(
|
393
|
+
end.must_raise(MiniTest::Assertion)
|
394
394
|
end
|
395
395
|
|
396
396
|
it "fails if there is no such field" do
|
397
397
|
proc do
|
398
398
|
html.must_have_unchecked_field('no such field')
|
399
|
-
end.must_raise(
|
399
|
+
end.must_raise(MiniTest::Assertion)
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
@@ -404,7 +404,7 @@ describe CapybaraMinitestSpec do
|
|
404
404
|
it "fails if there is such a field and it is not checked" do
|
405
405
|
proc do
|
406
406
|
html.wont_have_unchecked_field('unchecked field')
|
407
|
-
end.must_raise(
|
407
|
+
end.must_raise(MiniTest::Assertion)
|
408
408
|
end
|
409
409
|
|
410
410
|
it "passes if there is such a field but it is checked" do
|
@@ -427,7 +427,7 @@ describe CapybaraMinitestSpec do
|
|
427
427
|
it "fails if there is no such select" do
|
428
428
|
proc do
|
429
429
|
html.must_have_select('No such Select box')
|
430
|
-
end.must_raise(
|
430
|
+
end.must_raise(MiniTest::Assertion)
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
@@ -441,12 +441,12 @@ describe CapybaraMinitestSpec do
|
|
441
441
|
it "fails if there is no such select" do
|
442
442
|
proc do
|
443
443
|
html.must_have_table('No such Table')
|
444
|
-
end.must_raise(
|
444
|
+
end.must_raise(MiniTest::Assertion)
|
445
445
|
end
|
446
446
|
end
|
447
447
|
|
448
448
|
describe 'failure message' do
|
449
|
-
it 'shows matcher name and args' do
|
449
|
+
it 'for assert shows matcher name and args' do
|
450
450
|
begin
|
451
451
|
'actual'.must_have_css('expected', :count => 1)
|
452
452
|
rescue MiniTest::Assertion => ex
|
@@ -456,5 +456,16 @@ describe CapybaraMinitestSpec do
|
|
456
456
|
end
|
457
457
|
assert_equal 'Matcher failed: has_css?("expected", {:count=>1})', exception.message
|
458
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
|
459
470
|
end
|
460
471
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapybaraMiniTestSpec::Matcher do
|
4
|
+
|
5
|
+
let(:matcher) { CapybaraMiniTestSpec::Matcher.new(:has_css?) }
|
6
|
+
|
7
|
+
it 'should define an assertion' do
|
8
|
+
MiniTest::Assertions.public_instance_methods.must_include(:assert_page_has_css)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should define a refutation' do
|
12
|
+
MiniTest::Assertions.public_instance_methods.must_include(:refute_page_has_css)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should define positive expectation' do
|
16
|
+
MiniTest::Expectations.public_instance_methods.must_include(:must_have_css)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should define negative expectation' do
|
20
|
+
MiniTest::Expectations.public_instance_methods.must_include(:wont_have_css)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should wrap the asserted object in a Capybara::Node::Simple' do
|
24
|
+
matcher.send(:wrap, '').must_be_instance_of(Capybara::Node::Simple)
|
25
|
+
end
|
26
|
+
|
27
|
+
it '#test returns true when test passes' do
|
28
|
+
test_result = matcher.test('<h1>Test</h1>', 'h1', {:count => 1})
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#test returns false when test fails' do
|
32
|
+
test_result = matcher.test('<h1>Test</h1>', 'h2', {:count => 1})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#failure_message with 'assert' arg returns positive assertion failure message" do
|
36
|
+
message = CapybaraMiniTestSpec::Matcher.failure_message('assert', :has_css?, {:option => 1})
|
37
|
+
message.must_equal 'Matcher failed: has_css?({:option=>1})'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#failure_message with 'refute' arg returns negative assertion failure message" do
|
41
|
+
message = CapybaraMiniTestSpec::Matcher.failure_message('refute', :has_css?, {:option => 1})
|
42
|
+
message.must_equal 'Matcher should have failed: has_css?({:option=>1})'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/spec_helper.rb
CHANGED
@@ -5,12 +5,15 @@ require 'capybara/dsl'
|
|
5
5
|
|
6
6
|
require 'capybara_minitest_spec'
|
7
7
|
|
8
|
+
# Make all specs a subclass of MiniTest::Spec.
|
8
9
|
MiniTest::Spec.register_spec_type //, MiniTest::Spec
|
9
10
|
|
11
|
+
# Setup Rack test app.
|
10
12
|
$LOAD_PATH << File.join(__FILE__, '../../test_app')
|
11
13
|
require 'test_app'
|
12
14
|
Capybara.app = TestApp
|
13
15
|
|
16
|
+
# Set Capybara default selector to xpath.
|
14
17
|
class MiniTest::Spec
|
15
18
|
before :each do
|
16
19
|
Capybara.configure do |config|
|
@@ -18,11 +21,3 @@ class MiniTest::Spec
|
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
21
|
-
|
22
|
-
class Proc
|
23
|
-
include MiniTest::Assertions
|
24
|
-
# TODO: Replace this with a real assertion that checks the message.
|
25
|
-
def must_raise(exception_or_message)
|
26
|
-
exception = assert_raises(MiniTest::Assertion, &self)
|
27
|
-
end
|
28
|
-
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: capybara_minitest_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jared Ning
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-27 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -65,8 +65,10 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- capybara_minitest_spec.gemspec
|
67
67
|
- lib/capybara_minitest_spec.rb
|
68
|
+
- lib/capybara_minitest_spec/matcher.rb
|
68
69
|
- lib/capybara_minitest_spec/version.rb
|
69
|
-
- test/
|
70
|
+
- test/capybara_node_matchers_spec.rb
|
71
|
+
- test/matcher_spec.rb
|
70
72
|
- test/spec_helper.rb
|
71
73
|
- test_app/driver.rb
|
72
74
|
- test_app/fixtures/capybara.jpg
|
@@ -154,5 +156,6 @@ signing_key:
|
|
154
156
|
specification_version: 3
|
155
157
|
summary: MiniTest::Spec expectations for Capybara node matchers.
|
156
158
|
test_files:
|
157
|
-
- test/
|
159
|
+
- test/capybara_node_matchers_spec.rb
|
160
|
+
- test/matcher_spec.rb
|
158
161
|
- test/spec_helper.rb
|