minitest-capybara 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5d8349d1840c9e41fe11bbad48becf9e5528d6f
4
- data.tar.gz: 6bc1d2578e4463b58ea58209234d03615c5476c5
3
+ metadata.gz: d72ba938f51df7396ae9914fa39707d848c25d28
4
+ data.tar.gz: 8e49ad4b12040cdac1d8e09c9425dd8ad84d9370
5
5
  SHA512:
6
- metadata.gz: 9c189863a60328620e1bcfb47c472f15c2dc1f4482cfa440c6a8fc6feb0a5ba8c519bbff2ddf756190aa62342c5b6571365ba04f477537882d4d57d611b1c836
7
- data.tar.gz: d4afd15a1059f04230e9805ee8d02ef0e02b9639bfb62aa3623abbaa553cf859a844596cca081a3ce8096bbda3f48b6df1f0fe800bc5b4e0f1f59a71d98910d1
6
+ metadata.gz: 7cc687f847b99ef3a40c91347e863229d42039dcf73d70f224cc97a9950d8b5a3a18f6954e36bb0ab8aecc02ebf8bc1f8217ea24825d052f71abbda740870bfb
7
+ data.tar.gz: b0329fb9909f786c1087e2689ff5adcbd7036d4af8b6fc8af81f92a62ab345b945084803fbe26bc4837eb2d7e4b69412943c0c91aa0a882a40a7a3be8feaca3b
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - jruby-19mode
5
+ - rbx-19mode
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in minitest-matchers-capybara.gemspec
4
4
  gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Wojciech Mach
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # minitest-capybara
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/wojtekmach/minitest-capybara.png?branch=master)](http://travis-ci.org/wojtekmach/minitest-capybara)
4
+
3
5
  Capybara matchers support for minitest unit & spec
4
6
 
5
7
  ## Why?
@@ -41,7 +43,7 @@ require "capybara/rails"
41
43
  # for just minitest/unit
42
44
  class AcceptanceTest < Minitest::Unit::TestCase
43
45
  include Capybara::DSL
44
- include Minitest::Capybara::Assertions
46
+ include Capybara::Assertions
45
47
 
46
48
  def teardown
47
49
  Capybara.reset_session!
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require "rake/testtask"
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << 'lib'
6
+ t.libs << 'test'
6
7
  t.pattern = 'test/**/*_test.rb'
7
8
  t.verbose = false
8
9
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -0,0 +1,293 @@
1
+ module Capybara
2
+ module Assertions
3
+ def self.included(base)
4
+ raise "Make sure to include Capybara::Minitest::Assertions after Capybara::DSL" unless base < Capybara::DSL
5
+ end
6
+
7
+ def assert_text(*args)
8
+ node, *args = prepare_args(args)
9
+ assert has_text?(*args), message { "Expected to include #{args.first.inspect}" }
10
+ end
11
+ alias_method :assert_content, :assert_text
12
+
13
+ def refute_text(*args)
14
+ node, *args = prepare_args(args)
15
+ assert has_no_text?(*args), message { "Expected not to include #{args.first.inspect}" }
16
+ end
17
+ alias_method :assert_no_text, :refute_text
18
+ alias_method :refute_content, :refute_text
19
+ alias_method :assert_no_content, :refute_text
20
+
21
+ def assert_selector(*args)
22
+ node, *args = prepare_args(args)
23
+ node.assert_selector(*args)
24
+ rescue Capybara::ExpectationNotMet => e
25
+ assert false, e.message
26
+ end
27
+
28
+ def refute_selector(*args)
29
+ node, *args = prepare_args(args)
30
+ node.assert_no_selector(*args)
31
+ rescue Capybara::ExpectationNotMet => e
32
+ assert false, e.message
33
+ end
34
+ alias_method :assert_no_selector, :refute_selector
35
+
36
+ ruby = ""
37
+ (Minitest::Capybara.assertions - %w[text content selector]).each do |assertion|
38
+ ruby << <<-RUBY
39
+ def assert_#{assertion}(*args)
40
+ node, *args = prepare_args(args)
41
+ assert node.has_#{assertion}?(*args), message { Capybara::Helpers.failure_message(*args) }
42
+ end
43
+ RUBY
44
+ end
45
+ (Minitest::Capybara.refutations - %w[text content selector]).each do |refutation|
46
+ ruby << <<-RUBY
47
+ def refute_#{refutation}(*args)
48
+ node, *args = prepare_args(args)
49
+ assert node.has_no_#{refutation}?(*args), message { Capybara::Helpers.failure_message(*args) }
50
+ end
51
+ alias_method :assert_no_#{refutation}, :refute_#{refutation}
52
+ RUBY
53
+ end
54
+ class_eval(ruby)
55
+
56
+ ##
57
+ # Assertion that there is button
58
+ #
59
+ # see Capybara::Assertions#refute_button
60
+ # see Capybara::Assertions#assert_no_button
61
+ # see Capybara::expectations#must_have_button
62
+ # see Capybara::expectations#wont_have_button
63
+ # :method: assert_button
64
+
65
+ ##
66
+ # Assertion that there is no button
67
+ #
68
+ # see Capybara::Assertions#assert_button
69
+ # see Capybara::expectations#must_have_button
70
+ # see Capybara::expectations#wont_have_button
71
+ # :method: refute_button
72
+ # :alias: assert_no_button
73
+
74
+
75
+ ##
76
+ # Assertion that there is checked_field
77
+ #
78
+ # see Capybara::Assertions#refute_checked_field
79
+ # see Capybara::Assertions#assert_no_checked_field
80
+ # see Capybara::expectations#must_have_checked_field
81
+ # see Capybara::expectations#wont_have_checked_field
82
+ # :method: assert_checked_field
83
+
84
+ ##
85
+ # Assertion that there is no checked_field
86
+ #
87
+ # see Capybara::Assertions#assert_checked_field
88
+ # see Capybara::expectations#must_have_checked_field
89
+ # see Capybara::expectations#wont_have_checked_field
90
+ # :method: refute_checked_field
91
+ # :alias: assert_no_checked_field
92
+
93
+
94
+ ##
95
+ # Assertion that there is content
96
+ #
97
+ # see Capybara::Assertions#refute_content
98
+ # see Capybara::Assertions#assert_no_content
99
+ # see Capybara::expectations#must_have_content
100
+ # see Capybara::expectations#wont_have_content
101
+ # :method: assert_content
102
+
103
+ ##
104
+ # Assertion that there is no content
105
+ #
106
+ # see Capybara::Assertions#assert_content
107
+ # see Capybara::expectations#must_have_content
108
+ # see Capybara::expectations#wont_have_content
109
+ # :method: refute_content
110
+ # :alias: assert_no_content
111
+
112
+
113
+ ##
114
+ # Assertion that there is css
115
+ #
116
+ # see Capybara::Assertions#refute_css
117
+ # see Capybara::Assertions#assert_no_css
118
+ # see Capybara::expectations#must_have_css
119
+ # see Capybara::expectations#wont_have_css
120
+ # :method: assert_css
121
+
122
+ ##
123
+ # Assertion that there is no css
124
+ #
125
+ # see Capybara::Assertions#assert_css
126
+ # see Capybara::expectations#must_have_css
127
+ # see Capybara::expectations#wont_have_css
128
+ # :method: refute_css
129
+ # :alias: assert_no_css
130
+
131
+
132
+ ##
133
+ # Assertion that there is field
134
+ #
135
+ # see Capybara::Assertions#refute_field
136
+ # see Capybara::Assertions#assert_no_field
137
+ # see Capybara::expectations#must_have_field
138
+ # see Capybara::expectations#wont_have_field
139
+ # :method: assert_field
140
+
141
+ ##
142
+ # Assertion that there is no field
143
+ #
144
+ # see Capybara::Assertions#assert_field
145
+ # see Capybara::expectations#must_have_field
146
+ # see Capybara::expectations#wont_have_field
147
+ # :method: refute_field
148
+ # :alias: assert_no_field
149
+
150
+
151
+ ##
152
+ # Assertion that there is link
153
+ #
154
+ # see Capybara::Assertions#refute_link
155
+ # see Capybara::Assertions#assert_no_link
156
+ # see Capybara::expectations#must_have_link
157
+ # see Capybara::expectations#wont_have_link
158
+ # :method: assert_link
159
+
160
+ ##
161
+ # Assertion that there is no link
162
+ #
163
+ # see Capybara::Assertions#assert_link
164
+ # see Capybara::expectations#must_have_link
165
+ # see Capybara::expectations#wont_have_link
166
+ # :method: refute_link
167
+ # :alias: assert_no_link
168
+
169
+
170
+ ##
171
+ # Assertion that there is select
172
+ #
173
+ # see Capybara::Assertions#refute_select
174
+ # see Capybara::Assertions#assert_no_select
175
+ # see Capybara::expectations#must_have_select
176
+ # see Capybara::expectations#wont_have_select
177
+ # :method: assert_select
178
+
179
+ ##
180
+ # Assertion that there is no select
181
+ #
182
+ # see Capybara::Assertions#assert_select
183
+ # see Capybara::expectations#must_have_select
184
+ # see Capybara::expectations#wont_have_select
185
+ # :method: refute_select
186
+ # :alias: assert_no_select
187
+
188
+
189
+ ##
190
+ # Assertion that there is selector
191
+ #
192
+ # see Capybara::Assertions#refute_selector
193
+ # see Capybara::Assertions#assert_no_selector
194
+ # see Capybara::expectations#must_have_selector
195
+ # see Capybara::expectations#wont_have_selector
196
+ # :method: assert_selector
197
+
198
+ ##
199
+ # Assertion that there is no selector
200
+ #
201
+ # see Capybara::Assertions#assert_selector
202
+ # see Capybara::expectations#must_have_selector
203
+ # see Capybara::expectations#wont_have_selector
204
+ # :method: refute_selector
205
+ # :alias: assert_no_selector
206
+
207
+
208
+ ##
209
+ # Assertion that there is table
210
+ #
211
+ # see Capybara::Assertions#refute_table
212
+ # see Capybara::Assertions#assert_no_table
213
+ # see Capybara::expectations#must_have_table
214
+ # see Capybara::expectations#wont_have_table
215
+ # :method: assert_table
216
+
217
+ ##
218
+ # Assertion that there is no table
219
+ #
220
+ # see Capybara::Assertions#assert_table
221
+ # see Capybara::expectations#must_have_table
222
+ # see Capybara::expectations#wont_have_table
223
+ # :method: refute_table
224
+ # :alias: assert_no_table
225
+
226
+
227
+ ##
228
+ # Assertion that there is text
229
+ #
230
+ # see Capybara::Assertions#refute_text
231
+ # see Capybara::Assertions#assert_no_text
232
+ # see Capybara::expectations#must_have_text
233
+ # see Capybara::expectations#wont_have_text
234
+ # :method: assert_text
235
+
236
+ ##
237
+ # Assertion that there is no text
238
+ #
239
+ # see Capybara::Assertions#assert_text
240
+ # see Capybara::expectations#must_have_text
241
+ # see Capybara::expectations#wont_have_text
242
+ # :method: refute_text
243
+ # :alias: assert_no_text
244
+
245
+
246
+ ##
247
+ # Assertion that there is unchecked_field
248
+ #
249
+ # see Capybara::Assertions#refute_unchecked_field
250
+ # see Capybara::Assertions#assert_no_unchecked_field
251
+ # see Capybara::expectations#must_have_unchecked_field
252
+ # see Capybara::expectations#wont_have_unchecked_field
253
+ # :method: assert_unchecked_field
254
+
255
+ ##
256
+ # Assertion that there is no unchecked_field
257
+ #
258
+ # see Capybara::Assertions#assert_unchecked_field
259
+ # see Capybara::expectations#must_have_unchecked_field
260
+ # see Capybara::expectations#wont_have_unchecked_field
261
+ # :method: refute_unchecked_field
262
+ # :alias: assert_no_unchecked_field
263
+
264
+
265
+ ##
266
+ # Assertion that there is xpath
267
+ #
268
+ # see Capybara::Assertions#refute_xpath
269
+ # see Capybara::Assertions#assert_no_xpath
270
+ # see Capybara::expectations#must_have_xpath
271
+ # see Capybara::expectations#wont_have_xpath
272
+ # :method: assert_xpath
273
+
274
+ ##
275
+ # Assertion that there is no xpath
276
+ #
277
+ # see Capybara::Assertions#assert_xpath
278
+ # see Capybara::expectations#must_have_xpath
279
+ # see Capybara::expectations#wont_have_xpath
280
+ # :method: refute_xpath
281
+ # :alias: assert_no_xpath
282
+
283
+ private
284
+
285
+ def prepare_args(args)
286
+ if args.first.is_a?(Capybara::Session) || args.first.kind_of?(Capybara::Node::Base)
287
+ args
288
+ else
289
+ [page, *args]
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,248 @@
1
+ require "minitest/spec"
2
+
3
+ module Capybara
4
+ module Expectations
5
+ Minitest::Capybara.assertions.each do |assertion|
6
+ infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
7
+ end
8
+
9
+ Minitest::Capybara.refutations.each do |refutation|
10
+ infect_an_assertion "refute_#{refutation}", "wont_have_#{refutation}", :reverse
11
+ end
12
+
13
+ ##
14
+ # Expectation that there is button
15
+ #
16
+ # see Capybara::Expectations#wont_have_button
17
+ # see Capybara::Assertions#assert_button
18
+ # see Capybara::Assertions#refute_button
19
+ # see Capybara::Assertions#assert_no_button
20
+ # :method: must_have_button
21
+
22
+ ##
23
+ # Expectation that there is no button
24
+ #
25
+ # see Capybara::Expectations#must_have_button
26
+ # see Capybara::Assertions#assert_button
27
+ # see Capybara::Assertions#refute_button
28
+ # see Capybara::Assertions#assert_no_button
29
+ # :method: wont_have_button
30
+
31
+
32
+ ##
33
+ # Expectation that there is checked_field
34
+ #
35
+ # see Capybara::Expectations#wont_have_checked_field
36
+ # see Capybara::Assertions#assert_checked_field
37
+ # see Capybara::Assertions#refute_checked_field
38
+ # see Capybara::Assertions#assert_no_checked_field
39
+ # :method: must_have_checked_field
40
+
41
+ ##
42
+ # Expectation that there is no checked_field
43
+ #
44
+ # see Capybara::Expectations#must_have_checked_field
45
+ # see Capybara::Assertions#assert_checked_field
46
+ # see Capybara::Assertions#refute_checked_field
47
+ # see Capybara::Assertions#assert_no_checked_field
48
+ # :method: wont_have_checked_field
49
+
50
+
51
+ ##
52
+ # Expectation that there is content
53
+ #
54
+ # see Capybara::Expectations#wont_have_content
55
+ # see Capybara::Assertions#assert_content
56
+ # see Capybara::Assertions#refute_content
57
+ # see Capybara::Assertions#assert_no_content
58
+ # :method: must_have_content
59
+
60
+ ##
61
+ # Expectation that there is no content
62
+ #
63
+ # see Capybara::Expectations#must_have_content
64
+ # see Capybara::Assertions#assert_content
65
+ # see Capybara::Assertions#refute_content
66
+ # see Capybara::Assertions#assert_no_content
67
+ # :method: wont_have_content
68
+
69
+
70
+ ##
71
+ # Expectation that there is css
72
+ #
73
+ # see Capybara::Expectations#wont_have_css
74
+ # see Capybara::Assertions#assert_css
75
+ # see Capybara::Assertions#refute_css
76
+ # see Capybara::Assertions#assert_no_css
77
+ # :method: must_have_css
78
+
79
+ ##
80
+ # Expectation that there is no css
81
+ #
82
+ # see Capybara::Expectations#must_have_css
83
+ # see Capybara::Assertions#assert_css
84
+ # see Capybara::Assertions#refute_css
85
+ # see Capybara::Assertions#assert_no_css
86
+ # :method: wont_have_css
87
+
88
+
89
+ ##
90
+ # Expectation that there is field
91
+ #
92
+ # see Capybara::Expectations#wont_have_field
93
+ # see Capybara::Assertions#assert_field
94
+ # see Capybara::Assertions#refute_field
95
+ # see Capybara::Assertions#assert_no_field
96
+ # :method: must_have_field
97
+
98
+ ##
99
+ # Expectation that there is no field
100
+ #
101
+ # see Capybara::Expectations#must_have_field
102
+ # see Capybara::Assertions#assert_field
103
+ # see Capybara::Assertions#refute_field
104
+ # see Capybara::Assertions#assert_no_field
105
+ # :method: wont_have_field
106
+
107
+
108
+ ##
109
+ # Expectation that there is link
110
+ #
111
+ # see Capybara::Expectations#wont_have_link
112
+ # see Capybara::Assertions#assert_link
113
+ # see Capybara::Assertions#refute_link
114
+ # see Capybara::Assertions#assert_no_link
115
+ # :method: must_have_link
116
+
117
+ ##
118
+ # Expectation that there is no link
119
+ #
120
+ # see Capybara::Expectations#must_have_link
121
+ # see Capybara::Assertions#assert_link
122
+ # see Capybara::Assertions#refute_link
123
+ # see Capybara::Assertions#assert_no_link
124
+ # :method: wont_have_link
125
+
126
+
127
+ ##
128
+ # Expectation that there is select
129
+ #
130
+ # see Capybara::Expectations#wont_have_select
131
+ # see Capybara::Assertions#assert_select
132
+ # see Capybara::Assertions#refute_select
133
+ # see Capybara::Assertions#assert_no_select
134
+ # :method: must_have_select
135
+
136
+ ##
137
+ # Expectation that there is no select
138
+ #
139
+ # see Capybara::Expectations#must_have_select
140
+ # see Capybara::Assertions#assert_select
141
+ # see Capybara::Assertions#refute_select
142
+ # see Capybara::Assertions#assert_no_select
143
+ # :method: wont_have_select
144
+
145
+
146
+ ##
147
+ # Expectation that there is selector
148
+ #
149
+ # see Capybara::Expectations#wont_have_selector
150
+ # see Capybara::Assertions#assert_selector
151
+ # see Capybara::Assertions#refute_selector
152
+ # see Capybara::Assertions#assert_no_selector
153
+ # :method: must_have_selector
154
+
155
+ ##
156
+ # Expectation that there is no selector
157
+ #
158
+ # see Capybara::Expectations#must_have_selector
159
+ # see Capybara::Assertions#assert_selector
160
+ # see Capybara::Assertions#refute_selector
161
+ # see Capybara::Assertions#assert_no_selector
162
+ # :method: wont_have_selector
163
+
164
+
165
+ ##
166
+ # Expectation that there is table
167
+ #
168
+ # see Capybara::Expectations#wont_have_table
169
+ # see Capybara::Assertions#assert_table
170
+ # see Capybara::Assertions#refute_table
171
+ # see Capybara::Assertions#assert_no_table
172
+ # :method: must_have_table
173
+
174
+ ##
175
+ # Expectation that there is no table
176
+ #
177
+ # see Capybara::Expectations#must_have_table
178
+ # see Capybara::Assertions#assert_table
179
+ # see Capybara::Assertions#refute_table
180
+ # see Capybara::Assertions#assert_no_table
181
+ # :method: wont_have_table
182
+
183
+
184
+ ##
185
+ # Expectation that there is text
186
+ #
187
+ # see Capybara::Expectations#wont_have_text
188
+ # see Capybara::Assertions#assert_text
189
+ # see Capybara::Assertions#refute_text
190
+ # see Capybara::Assertions#assert_no_text
191
+ # :method: must_have_text
192
+
193
+ ##
194
+ # Expectation that there is no text
195
+ #
196
+ # see Capybara::Expectations#must_have_text
197
+ # see Capybara::Assertions#assert_text
198
+ # see Capybara::Assertions#refute_text
199
+ # see Capybara::Assertions#assert_no_text
200
+ # :method: wont_have_text
201
+
202
+
203
+ ##
204
+ # Expectation that there is unchecked_field
205
+ #
206
+ # see Capybara::Expectations#wont_have_unchecked_field
207
+ # see Capybara::Assertions#assert_unchecked_field
208
+ # see Capybara::Assertions#refute_unchecked_field
209
+ # see Capybara::Assertions#assert_no_unchecked_field
210
+ # :method: must_have_unchecked_field
211
+
212
+ ##
213
+ # Expectation that there is no unchecked_field
214
+ #
215
+ # see Capybara::Expectations#must_have_unchecked_field
216
+ # see Capybara::Assertions#assert_unchecked_field
217
+ # see Capybara::Assertions#refute_unchecked_field
218
+ # see Capybara::Assertions#assert_no_unchecked_field
219
+ # :method: wont_have_unchecked_field
220
+
221
+
222
+ ##
223
+ # Expectation that there is xpath
224
+ #
225
+ # see Capybara::Expectations#wont_have_xpath
226
+ # see Capybara::Assertions#assert_xpath
227
+ # see Capybara::Assertions#refute_xpath
228
+ # see Capybara::Assertions#assert_no_xpath
229
+ # :method: must_have_xpath
230
+
231
+ ##
232
+ # Expectation that there is no xpath
233
+ #
234
+ # see Capybara::Expectations#must_have_xpath
235
+ # see Capybara::Assertions#assert_xpath
236
+ # see Capybara::Assertions#refute_xpath
237
+ # see Capybara::Assertions#assert_no_xpath
238
+ # :method: wont_have_xpath
239
+ end
240
+ end
241
+
242
+ class Capybara::Session
243
+ include Capybara::Expectations unless ENV["MT_NO_EXPECTATIONS"]
244
+ end
245
+
246
+ class Capybara::Node::Base
247
+ include Capybara::Expectations unless ENV["MT_NO_EXPECTATIONS"]
248
+ end
@@ -1,83 +1,35 @@
1
- require 'minitest/capybara/version'
2
- require 'minitest/spec'
1
+ require "minitest/capybara/version"
2
+ require "capybara"
3
3
 
4
- module Minitest::Capybara
5
- module Assertions
6
- METHODS = Capybara::Session::NODE_METHODS.grep(/^has_/).map { |s| s.to_s.match(/has_(.*?)\?/)[1] }
7
-
8
- def self.included(base)
9
- raise "Make sure to include Capybara::Minitest::Assertions after Capybara::DSL" unless base < Capybara::DSL
10
- end
11
-
12
- def self.assertion_name(method)
13
- method.start_with?('no_') ? "refute_#{method.gsub(/^no_/, '')}" : "assert_#{method}"
14
- end
15
-
16
- def assert_text(*args)
17
- node, *args = prepare_args(args)
18
- assert has_text?(*args), message { "Expected to include #{args.first.inspect}" }
19
- end
20
- alias_method :assert_content, :assert_text
21
-
22
- def refute_text(*args)
23
- node, *args = prepare_args(args)
24
- assert has_no_text?(*args), message { "Expected not to include #{args.first.inspect}" }
4
+ module Minitest
5
+ module Capybara
6
+ @@assertions = ::Capybara::Session::NODE_METHODS.grep(/^has_/).map { |s| s.to_s.match(/^has_(.*?)\?/)[1] }
7
+ @@refutations = @@assertions.grep(/^no_/)
8
+ @@assertions = (@@assertions - @@refutations).sort
9
+ @@refutations = @@refutations.map { |s| s.match(/^no_(.*)/)[1] }.sort
10
+ def self.assertions
11
+ @@assertions
25
12
  end
26
- alias_method :refute_content, :refute_text
27
-
28
- def assert_selector(*args)
29
- node, *args = prepare_args(args)
30
- node.assert_selector(*args)
31
- rescue Capybara::ExpectationNotMet => e
32
- assert false, e.message
33
- end
34
-
35
- def refute_selector(*args)
36
- node, *args = prepare_args(args)
37
- node.assert_no_selector(*args)
38
- rescue Capybara::ExpectationNotMet => e
39
- assert false, e.message
40
- end
41
-
42
- ruby = ""
43
- (METHODS - %w[text no_text content no_content selector no_selector]).each do |method|
44
- assertion_name = method.start_with?('no') ? "refute_#{method.gsub(/^no_/, '')}" : "assert_#{method}"
45
-
46
- ruby << <<-RUBY
47
- def #{assertion_name}(*args)
48
- node, *args = prepare_args(args)
49
- assert node.has_#{method}?(*args), message { Capybara::Helpers.failure_message(*args) }
50
- end
51
- RUBY
13
+ def self.refutations
14
+ @@refutations
52
15
  end
53
- class_eval(ruby)
54
-
55
- private
16
+ end
17
+ end
56
18
 
57
- def prepare_args(args)
58
- if args.first.is_a?(Capybara::Session) || args.first.kind_of?(Capybara::Node::Base)
59
- args
19
+ # Need to be required after Minitest::Capybara is defined
20
+ require "capybara/assertions"
21
+ require "capybara/expectations"
22
+
23
+ # :stopdoc:
24
+ module Minitest
25
+ module Capybara
26
+ def self.const_missing const
27
+ if :Assertions == const
28
+ warn "Minitest::Capybara::Assertions is deprecated. Please use Capybara::Assertions instead."
29
+ ::Capybara::Assertions
60
30
  else
61
- [page, *args]
31
+ super const
62
32
  end
63
33
  end
64
34
  end
65
-
66
- module Expectations
67
- def self.expectation_name(method)
68
- method.start_with?('no_') ? "wont_have_#{method.gsub(/^no_/, '')}" : "must_have_#{method}"
69
- end
70
-
71
- Assertions::METHODS.each do |method|
72
- infect_an_assertion Assertions.assertion_name(method), expectation_name(method), :reverse
73
- end
74
- end
75
- end
76
-
77
- class Capybara::Session
78
- include Minitest::Capybara::Expectations
79
- end
80
-
81
- class Capybara::Node::Base
82
- include Minitest::Capybara::Expectations
83
35
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ Capybara.app = lambda { |env| [200, {}, "<div><h1>foo</h1><a href='/'>bar</a></div>"] }
4
+
5
+ describe "Assertions" do
6
+ include Capybara::DSL
7
+ include Capybara::Assertions
8
+
9
+ before do
10
+ visit "/"
11
+ end
12
+
13
+ it "defines all the assertions that Capybara does" do
14
+ Minitest::Capybara.assertions.each do |assertion|
15
+ assert self.respond_to?("assert_#{assertion}"),
16
+ "The assertion assert_#{assertion} is not defined."
17
+ end
18
+ end
19
+
20
+ it "defines all the refutations that Capybara does" do
21
+ Minitest::Capybara.refutations.each do |refutation|
22
+ assert self.respond_to?("refute_#{refutation}"),
23
+ "The assertion refute_#{refutation} is not defined."
24
+ end
25
+ end
26
+
27
+ it "defines all the negative assertions that Capybara does" do
28
+ Minitest::Capybara.refutations.each do |refutation|
29
+ assert self.respond_to?("assert_no_#{refutation}"),
30
+ "The assertion assert_no_#{refutation} is not defined."
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ Capybara.app = lambda { |env| [200, {}, "<div><h1>foo</h1><a href='/'>bar</a></div>"] }
4
+
5
+ describe "Expectations" do
6
+ include Capybara::DSL
7
+ include Capybara::Assertions
8
+
9
+ before do
10
+ visit "/"
11
+ end
12
+
13
+ it "defines all the must expectations that Capybara does" do
14
+ Minitest::Capybara.assertions.each do |assertion|
15
+ assert page.respond_to?("must_have_#{assertion}"),
16
+ "The expectation must_have_#{assertion} is not defined."
17
+ end
18
+ end
19
+
20
+ it "defines all the wont expectations that Capybara does" do
21
+ Minitest::Capybara.refutations.each do |refutation|
22
+ assert page.respond_to?("wont_have_#{refutation}"),
23
+ "The expectation wont_have_#{refutation} is not defined."
24
+ end
25
+ end
26
+ end
@@ -1,13 +1,10 @@
1
- require "minitest/autorun"
2
-
3
- require "capybara"
4
- require "minitest/capybara"
1
+ require 'test_helper'
5
2
 
6
3
  Capybara.app = lambda { |env| [200, {}, "<div><h1>foo</h1><a href='/'>bar</a></div>"] }
7
4
 
8
5
  describe "app" do
9
6
  include Capybara::DSL
10
- include Minitest::Capybara::Assertions
7
+ include Capybara::Assertions
11
8
 
12
9
  before do
13
10
  visit "/"
@@ -0,0 +1,2 @@
1
+ require "minitest/autorun"
2
+ require "minitest/capybara"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Mach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-30 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -60,15 +60,22 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - .travis.yml
63
64
  - Gemfile
65
+ - LICENSE.txt
64
66
  - README.md
65
67
  - Rakefile
66
68
  - VERSION
69
+ - lib/capybara/assertions.rb
70
+ - lib/capybara/expectations.rb
67
71
  - lib/minitest-capybara.rb
68
72
  - lib/minitest/capybara.rb
69
73
  - lib/minitest/capybara/version.rb
70
74
  - minitest-capybara.gemspec
75
+ - test/capybara/assertions_test.rb
76
+ - test/capybara/expectations_test.rb
71
77
  - test/minitest/capybara_test.rb
78
+ - test/test_helper.rb
72
79
  homepage: ''
73
80
  licenses: []
74
81
  metadata: {}
@@ -93,4 +100,7 @@ signing_key:
93
100
  specification_version: 4
94
101
  summary: Capybara matchers support for minitest unit and spec
95
102
  test_files:
103
+ - test/capybara/assertions_test.rb
104
+ - test/capybara/expectations_test.rb
96
105
  - test/minitest/capybara_test.rb
106
+ - test/test_helper.rb