capybara 2.12.1 → 2.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 366aecdcbfc57f6102bd9216645cfdb69dea2f0e
4
- data.tar.gz: 989edd37eea1f619de795362350584f25af60b17
3
+ metadata.gz: 266938107d80bacdd4f95cc21e79fe6b7af2e131
4
+ data.tar.gz: dac8ea7395988fc218da8a556df246db661125b0
5
5
  SHA512:
6
- metadata.gz: ccd1760a40ac203ebf7ba2b38104e64e9eea0446ccc596898b8467f5c0471f37e003ca84616c82843426928b6997d7be3b748beb85aa00e34a70573551027427
7
- data.tar.gz: 7d51a1a4fc3c405774710bd4eae7d922fa1957d5900f50c68a5f58c70f762d73d11ac00964654c7408320c10c4b401dea588e3eec35f9cc3f13482a42aca1362
6
+ metadata.gz: a548da527db279933776ebd86daa6ddf1d7e714bc9b22225959d58b67bbecfa8458f503cde377fc262f0d4442ef6d0f47a88a1bcf66efd58bc5014d80b80f87d
7
+ data.tar.gz: f040e322ba5e591dbc3546b0e5c7672f21b6e9eab99ff848780f42e1e1d9e5ce87bdfe242ae0dbb7a45b4ecb37611d3c1c1a202cedcc1e16cc00040114422213
data/History.md CHANGED
@@ -1,3 +1,15 @@
1
+ #Version 2.13.0
2
+ Release date: 2017-03-16
3
+
4
+ ### Added
5
+
6
+ * Selenium driver supports returning element(s) from evaluate_script [Thomas Walpole]
7
+ * rack_test driver supports click on checkboxes and radio buttons to change their states [Thomas Walpole]
8
+ * Support RSpec equivalent assertions and expectations for MiniTest [Thomas Walpole]
9
+
10
+ ### Foxed
11
+ * Editing of content editable children with selenium
12
+
1
13
  #Version 2.12.1
2
14
  Release date: 2017-02-16
3
15
 
data/README.md CHANGED
@@ -36,7 +36,8 @@ You can read more about the missing features [here](https://github.com/teamcapyb
36
36
  - [Using Capybara with Cucumber](#using-capybara-with-cucumber)
37
37
  - [Using Capybara with RSpec](#using-capybara-with-rspec)
38
38
  - [Using Capybara with Test::Unit](#using-capybara-with-testunit)
39
- - [Using Capybara with MiniTest::Spec](#using-capybara-with-minitestspec)
39
+ - [Using Capybara with Minitest](#using-capybara-with-minitest)
40
+ - [Using Capybara with Minitest::Spec](#using-capybara-with-minitestspec)
40
41
  - [Drivers](#drivers)
41
42
  - [Selecting the Driver](#selecting-the-driver)
42
43
  - [RackTest](#racktest)
@@ -242,14 +243,37 @@ end
242
243
 
243
244
  ## <a name="using-capybara-with-testunit"></a>Using Capybara with Test::Unit
244
245
 
246
+ * If you are using `Test::Unit`, define a base class for your Capybara tests
247
+ like so:
248
+
249
+ ```ruby
250
+ require 'capybara/dsl'
251
+
252
+ class CapybaraTestCase < Test::Unit::TestCase
253
+ include Capybara::DSL
254
+
255
+ def teardown
256
+ Capybara.reset_sessions!
257
+ Capybara.use_default_driver
258
+ end
259
+ end
260
+ ```
261
+
262
+ ## <a name="using-capybara-with-minitest"></a>Using Capybara with Minitest
263
+
245
264
  * If you are using Rails, add the following code in your `test_helper.rb`
246
265
  file to make Capybara available in all test cases deriving from
247
266
  `ActionDispatch::IntegrationTest`:
248
267
 
249
268
  ```ruby
269
+ require 'capybara/rails'
270
+ require 'capybara/minitest'
271
+
250
272
  class ActionDispatch::IntegrationTest
251
273
  # Make the Capybara DSL available in all integration tests
252
274
  include Capybara::DSL
275
+ # Make `assert_*` methods behave like Minitest assertions
276
+ include Capybara::Minitest::Assertions
253
277
 
254
278
  # Reset sessions and driver between tests
255
279
  # Use super wherever this method is redefined in your individual test classes
@@ -264,8 +288,11 @@ end
264
288
  so:
265
289
 
266
290
  ```ruby
267
- class CapybaraTestCase < Test::Unit::TestCase
291
+ require 'capybara/minitest'
292
+
293
+ class CapybaraTestCase < Minitest::Test
268
294
  include Capybara::DSL
295
+ include Capybara::Minitest::Assertions
269
296
 
270
297
  def teardown
271
298
  Capybara.reset_sessions!
@@ -291,14 +318,9 @@ class BlogTest < ActionDispatch::IntegrationTest
291
318
  end
292
319
  ```
293
320
 
294
- ## <a name="using-capybara-with-minitestspec"></a>Using Capybara with MiniTest::Spec
295
-
296
- Set up your base class as with Test::Unit. (On Rails, the right base class
297
- could be something other than ActionDispatch::IntegrationTest.)
321
+ ## <a name="using-capybara-with-minitestspec"></a>Using Capybara with Minitest::Spec
298
322
 
299
- The capybara_minitest_spec gem ([GitHub](https://github.com/ordinaryzelig/capybara_minitest_spec),
300
- [rubygems.org](https://rubygems.org/gems/capybara_minitest_spec)) provides MiniTest::Spec
301
- expectations for Capybara. For example:
323
+ Follow the above instructions for Minitest and additionally require capybara/minitest/spec
302
324
 
303
325
  ```ruby
304
326
  page.must_have_content('Important!')
@@ -0,0 +1,297 @@
1
+ # frozen_string_literal: true
2
+ require 'minitest'
3
+ require 'capybara/dsl'
4
+
5
+ module Capybara
6
+ module Minitest
7
+ module Assertions
8
+ ## Assert text exists
9
+ # see {Capybara::Node::Matchers#assert_text}
10
+ def assert_text(*args)
11
+ self.assertions += 1
12
+ subject, *args = determine_subject(args)
13
+ subject.assert_text(*args)
14
+ rescue Capybara::ExpectationNotMet => e
15
+ raise ::Minitest::Assertion, e.message
16
+ end
17
+ alias_method :assert_content, :assert_text
18
+
19
+ ## Assert text does not exist
20
+ # see {Capybara::Node::Matchers#assert_no_text}
21
+ def assert_no_text(*args)
22
+ self.assertions += 1
23
+ subject, *args = determine_subject(args)
24
+ subject.assert_no_text(*args)
25
+ rescue Capybara::ExpectationNotMet => e
26
+ raise ::Minitest::Assertion, e.message
27
+ end
28
+ alias_method :refute_text, :assert_no_text
29
+ alias_method :refute_content, :refute_text
30
+ alias_method :assert_no_content, :refute_text
31
+
32
+ ## Assert selector exists on page
33
+ # see {Capybara::Node::Matchers#assert_selector}
34
+ def assert_selector(*args, &optional_filter_block)
35
+ self.assertions +=1
36
+ subject, *args = determine_subject(args)
37
+ subject.assert_selector(*args, &optional_filter_block)
38
+ rescue Capybara::ExpectationNotMet => e
39
+ raise ::Minitest::Assertion, e.message
40
+ end
41
+
42
+ ## Assert selector does not exist on page
43
+ # see {Capybara::Node::Matchers#assert_no_selector}
44
+ def assert_no_selector(*args, &optional_filter_block)
45
+ self.assertions +=1
46
+ subject, *args = determine_subject(args)
47
+ subject.assert_no_selector(*args, &optional_filter_block)
48
+ rescue Capybara::ExpectationNotMet => e
49
+ raise ::Minitest::Assertion, e.message
50
+ end
51
+ alias_method :refute_selector, :assert_no_selector
52
+
53
+ ## Assert element matches selector
54
+ # see {Capybara::Node::Matchers#assert_matches_selector}
55
+ def assert_matches_selector(*args, &optional_filter_block)
56
+ self.assertions += 1
57
+ subject, *args = determine_subject(args)
58
+ subject.assert_matches_selector(*args, &optional_filter_block)
59
+ rescue Capybara::ExpectationNotMet => e
60
+ raise ::Minitest::Assertion, e.message
61
+ end
62
+
63
+ ## Assert element does not match selector
64
+ # see {Capybara::Node::Matchers#assert_not_matches_selector}
65
+ def assert_not_matches_selector(*args, &optional_filter_block)
66
+ self.assertions += 1
67
+ subject, *args = determine_subject(args)
68
+ subject.assert_not_matches_selector(*args, &optional_filter_block)
69
+ rescue Capybara::ExpectationNotMet => e
70
+ raise ::Minitest::Assertion, e.message
71
+ end
72
+ alias_method :refute_matches_selector, :assert_not_matches_selector
73
+
74
+ %w(title current_path).each do |selector_type|
75
+ define_method "assert_#{selector_type}" do |*args|
76
+ begin
77
+ self.assertions += 1
78
+ subject, *args = determine_subject(args)
79
+ subject.public_send("assert_#{selector_type}",*args)
80
+ rescue Capybara::ExpectationNotMet => e
81
+ raise ::Minitest::Assertion, e.message
82
+ end
83
+ end
84
+
85
+ define_method "assert_no_#{selector_type}" do |*args|
86
+ begin
87
+ self.assertions += 1
88
+ subject, *args = determine_subject(args)
89
+ subject.public_send("assert_no_#{selector_type}",*args)
90
+ rescue Capybara::ExpectationNotMet => e
91
+ raise ::Minitest::Assertion, e.message
92
+ end
93
+ end
94
+ alias_method "refute_#{selector_type}", "assert_no_#{selector_type}"
95
+ end
96
+
97
+ %w(xpath css link button field select table).each do |selector_type|
98
+ define_method "assert_#{selector_type}" do |*args, &optional_filter_block|
99
+ subject, *args = determine_subject(args)
100
+ locator, options = *args, {}
101
+ locator, options = nil, locator if locator.is_a? Hash
102
+ assert_selector(subject, selector_type.to_sym, locator, options, &optional_filter_block)
103
+ end
104
+
105
+ define_method "assert_no_#{selector_type}" do |*args, &optional_filter_block|
106
+ subject, *args = determine_subject(args)
107
+ locator, options = *args, {}
108
+ locator, options = nil, locator if locator.is_a? Hash
109
+ assert_no_selector(subject, selector_type.to_sym, locator, options, &optional_filter_block)
110
+ end
111
+ alias_method "refute_#{selector_type}", "assert_no_#{selector_type}"
112
+ end
113
+
114
+ %w(xpath css).each do |selector_type|
115
+ define_method "assert_matches_#{selector_type}" do |*args, &optional_filter_block|
116
+ subject, *args = determine_subject(args)
117
+ assert_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)
118
+ end
119
+
120
+ define_method "assert_not_matches_#{selector_type}" do |*args, &optional_filter_block|
121
+ subject, *args = determine_subject(args)
122
+ assert_not_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)
123
+ end
124
+ alias_method "refute_matches_#{selector_type}", "assert_not_matches_#{selector_type}"
125
+ end
126
+
127
+ %w(checked unchecked).each do |field_type|
128
+ define_method "assert_#{field_type}_field" do |*args, &optional_filter_block|
129
+ subject, *args = determine_subject(args)
130
+ locator, options = *args, {}
131
+ locator, options = nil, locator if locator.is_a? Hash
132
+ assert_selector(subject, :field, locator, options.merge(field_type.to_sym => true), &optional_filter_block)
133
+ end
134
+
135
+ define_method "assert_no_#{field_type}_field" do |*args, &optional_filter_block|
136
+ subject, *args = determine_subject(args)
137
+ locator, options = *args, {}
138
+ locator, options = nil, locator if locator.is_a? Hash
139
+ assert_no_selector(subject, :field, locator, options.merge(field_type.to_sym => true), &optional_filter_block)
140
+ end
141
+ alias_method "refute_#{field_type}_field", "assert_no_#{field_type}_field"
142
+ end
143
+
144
+ ##
145
+ # Assertion that there is xpath
146
+ #
147
+ # @!method assert_xpath
148
+ # see Capybara::Node::Matchers#has_xpath?
149
+
150
+ ##
151
+ # Assertion that there is no xpath
152
+ #
153
+ # @!method refute_xpath
154
+ # @!method assert_no_xpath
155
+ # see Capybara::Node::Matchers#has_no_xpath?
156
+
157
+ ##
158
+ # Assertion that there is css
159
+ #
160
+ # @!method assert_css
161
+ # see Capybara::Node::Matchers#has_css?
162
+
163
+ ##
164
+ # Assertion that there is no css
165
+ #
166
+ # @!method refute_css
167
+ # @!method assert_no_css
168
+ # see Capybara::Node::Matchers#has_no_css?
169
+
170
+ ##
171
+ # Assertion that there is link
172
+ #
173
+ # @!method assert_link
174
+ # see {Capybara::Node::Matchers#has_link?}
175
+
176
+ ##
177
+ # Assertion that there is no link
178
+ #
179
+ # @!method assert_no_link
180
+ # @!method refute_link
181
+ # see {Capybara::Node::Matchers#has_no_link?}
182
+
183
+ ##
184
+ # Assertion that there is button
185
+ #
186
+ # @!method assert_button
187
+ # see {Capybara::Node::Matchers#has_button?}
188
+
189
+ ##
190
+ # Assertion that there is no button
191
+ #
192
+ # @!method refute_button
193
+ # @!method assert_no_button
194
+ # see {Capybara::Node::Matchers#has_no_button?}
195
+
196
+ ##
197
+ # Assertion that there is field
198
+ #
199
+ # @!method assert_field
200
+ # see {Capybara::Node::Matchers#has_field?}
201
+
202
+ ##
203
+ # Assertion that there is no field
204
+ #
205
+ # @!method refute_field
206
+ # @!method assert_no_field
207
+ # see {Capybara::Node::Matchers#has_no_field?}
208
+
209
+ ##
210
+ # Assertion that there is checked_field
211
+ #
212
+ # @!method assert_checked_field
213
+ # see {Capybara::Node::Matchers#has_checked_field?}
214
+
215
+ ##
216
+ # Assertion that there is no checked_field
217
+ #
218
+ # @!method assert_no_checked_field
219
+ # @!method refute_chceked_field
220
+
221
+ ##
222
+ # Assertion that there is unchecked_field
223
+ #
224
+ # @!method assert_unchecked_field
225
+ # see {Capybara::Node::Matchers#has_unchecked_field?}
226
+
227
+ ##
228
+ # Assertion that there is no unchecked_field
229
+ #
230
+ # @!method assert_no_unchecked_field
231
+ # @!method refute_unchceked_field
232
+
233
+ ##
234
+ # Assertion that there is select
235
+ #
236
+ # @!method assert_select
237
+ # see {Capybara::Node::Matchers#has_select?}
238
+
239
+ ##
240
+ # Assertion that there is no select
241
+ #
242
+ # @!method refute_select
243
+ # @!method assert_no_select
244
+ # see {Capybara::Node::Matchers#has_no_select?}
245
+
246
+ ##
247
+ # Assertion that there is table
248
+ #
249
+ # @!method assert_table
250
+ # see {Capybara::Node::Matchers#has_table?}
251
+
252
+ ##
253
+ # Assertion that there is no table
254
+ #
255
+ # @!method refute_table
256
+ # @!method assert_no_table
257
+ # see {Capybara::Node::Matchers#has_no_table?}
258
+
259
+ ##
260
+ # Assertion that page title does match
261
+ #
262
+ # @!method assert_title
263
+ # see {Capybara::Node::DocumentMatchers#assert_title}
264
+
265
+ ##
266
+ # Assertion that page title does not match
267
+ #
268
+ # @!method refute_title
269
+ # @!method assert_no_title
270
+ # see {Capybara::Node::DocumentMatchers#assert_no_title}
271
+
272
+ ##
273
+ # Assertion that current path matches
274
+ #
275
+ # @!method assert_current_path
276
+ # see {Capybara::SessionMatchers#assert_current_path}
277
+
278
+ ##
279
+ # Assertion that current page does not match
280
+ #
281
+ # @!method refute_current_path
282
+ # @!method assert_no_current_path
283
+ # see {Capybara::SessionMatchers#assert_no_current_path}
284
+
285
+ private
286
+
287
+ def determine_subject(args)
288
+ case args.first
289
+ when Capybara::Session, Capybara::Node::Base, Capybara::Node::Simple
290
+ args
291
+ else
292
+ [page, *args]
293
+ end
294
+ end
295
+ end
296
+ end
297
+ end
@@ -0,0 +1,200 @@
1
+ require 'minitest/spec'
2
+
3
+ module Capybara
4
+ module Minitest
5
+ module Expectations
6
+ %w(text content title current_path).each do |assertion|
7
+ infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
8
+ infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
9
+ end
10
+
11
+ # Unfortunately infect_an_assertion doesn't pass through the optional filter block so we can't use it for these
12
+ %w(selector xpath css link button field select table checked_field unchecked_field).each do |assertion|
13
+ self.class_eval <<-EOM
14
+ def must_have_#{assertion} *args, &optional_filter_block
15
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).must_have_#{assertion}(*args, &optional_filter_block)
16
+ end
17
+
18
+ def wont_have_#{assertion} *args, &optional_filter_block
19
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).wont_have_#{assertion}(*args, &optional_filter_block)
20
+ end
21
+ EOM
22
+
23
+ ::Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 1
24
+ def must_have_#{assertion} *args, &optional_filter_block
25
+ ctx.assert_#{assertion}(target, *args, &optional_filter_block)
26
+ end
27
+
28
+ def wont_have_#{assertion} *args, &optional_filter_block
29
+ ctx.refute_#{assertion}(target, *args, &optional_filter_block)
30
+ end
31
+ EOM
32
+ end
33
+
34
+ %w(selector xpath css).each do |assertion|
35
+ self.class_eval <<-EOM
36
+ def must_match_#{assertion} *args, &optional_filter_block
37
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).must_match_#{assertion}(*args, &optional_filter_block)
38
+ end
39
+
40
+ def wont_match_#{assertion} *args, &optional_filter_block
41
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).wont_match_#{assertion}(*args, &optional_filter_block)
42
+ end
43
+ EOM
44
+
45
+ ::Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 1
46
+ def must_match_#{assertion} *args, &optional_filter_block
47
+ ctx.assert_matches_#{assertion}(target, *args, &optional_filter_block)
48
+ end
49
+
50
+ def wont_match_#{assertion} *args, &optional_filter_block
51
+ ctx.refute_matches_#{assertion}(target, *args, &optional_filter_block)
52
+ end
53
+ EOM
54
+ end
55
+
56
+ ##
57
+ # Expectation that there is xpath
58
+ #
59
+ # @!method must_have_xpath
60
+ # see Capybara::Node::Matchers#has_xpath?
61
+
62
+ ##
63
+ # Expectation that there is no xpath
64
+ #
65
+ # @!method wont_have_xpath
66
+ # see Capybara::Node::Matchers#has_no_xpath?
67
+
68
+ ##
69
+ # Expectation that there is css
70
+ #
71
+ # @!method must_have_css
72
+ # see Capybara::Node::Matchers#has_css?
73
+
74
+ ##
75
+ # Expectation that there is no css
76
+ #
77
+ # @!method wont_have_css
78
+ # see Capybara::Node::Matchers#has_no_css?
79
+
80
+ ##
81
+ # Expectation that there is link
82
+ #
83
+ # @!method must_have_link
84
+ # see {Capybara::Node::Matchers#has_link?}
85
+
86
+ ##
87
+ # Expectation that there is no link
88
+ #
89
+ # @!method wont_have_link
90
+ # see {Capybara::Node::Matchers#has_no_link?}
91
+
92
+ ##
93
+ # Expectation that there is button
94
+ #
95
+ # @!method must_have_button
96
+ # see {Capybara::Node::Matchers#has_button?}
97
+
98
+ ##
99
+ # Expectation that there is no button
100
+ #
101
+ # @!method wont_have_button
102
+ # see {Capybara::Node::Matchers#has_no_button?}
103
+
104
+ ##
105
+ # Expectation that there is field
106
+ #
107
+ # @!method must_have_field
108
+ # see {Capybara::Node::Matchers#has_field?}
109
+
110
+ ##
111
+ # Expectation that there is no field
112
+ #
113
+ # @!method wont_have_field
114
+ # see {Capybara::Node::Matchers#has_no_field?}
115
+
116
+ ##
117
+ # Expectation that there is checked_field
118
+ #
119
+ # @!method must_have_checked_field
120
+ # see {Capybara::Node::Matchers#has_checked_field?}
121
+
122
+ ##
123
+ # Expectation that there is no checked_field
124
+ #
125
+ # @!method wont_have_chceked_field
126
+
127
+ ##
128
+ # Expectation that there is unchecked_field
129
+ #
130
+ # @!method must_have_unchecked_field
131
+ # see {Capybara::Node::Matchers#has_unchecked_field?}
132
+
133
+ ##
134
+ # Expectation that there is no unchecked_field
135
+ #
136
+ # @!method wont_have_unchceked_field
137
+
138
+ ##
139
+ # Expectation that there is select
140
+ #
141
+ # @!method must_have_select
142
+ # see {Capybara::Node::Matchers#has_select?}
143
+
144
+ ##
145
+ # Expectation that there is no select
146
+ #
147
+ # @!method wont_have_select
148
+ # see {Capybara::Node::Matchers#has_no_select?}
149
+
150
+ ##
151
+ # Expectation that there is table
152
+ #
153
+ # @!method must_have_table
154
+ # see {Capybara::Node::Matchers#has_table?}
155
+
156
+ ##
157
+ # Expectation that there is no table
158
+ #
159
+ # @!method wont_have_table
160
+ # see {Capybara::Node::Matchers#has_no_table?}
161
+
162
+ ##
163
+ # Expectation that page title does match
164
+ #
165
+ # @!method must_have_title
166
+ # see {Capybara::Node::DocumentMatchers#assert_title}
167
+
168
+ ##
169
+ # Expectation that page title does not match
170
+ #
171
+ # @!method wont_have_title
172
+ # see {Capybara::Node::DocumentMatchers#assert_no_title}
173
+
174
+ ##
175
+ # Expectation that current path matches
176
+ #
177
+ # @!method must_have_current_path
178
+ # see {Capybara::SessionMatchers#assert_current_path}
179
+
180
+ ##
181
+ # Expectation that current page does not match
182
+ #
183
+ # @!method wont_have_current_path
184
+ # see {Capybara::SessionMatchers#assert_no_current_path}
185
+
186
+ end
187
+ end
188
+ end
189
+
190
+ class Capybara::Session
191
+ include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
192
+ end
193
+
194
+ class Capybara::Node::Base
195
+ include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
196
+ end
197
+
198
+ class Capybara::Node::Simple
199
+ include Capybara::Minitest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
200
+ end