capybara 3.32.0 → 3.35.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 +4 -4
- data/History.md +99 -15
- data/README.md +9 -4
- data/lib/capybara.rb +18 -8
- data/lib/capybara/config.rb +4 -6
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/helpers.rb +25 -1
- data/lib/capybara/minitest.rb +2 -3
- data/lib/capybara/minitest/spec.rb +14 -11
- data/lib/capybara/node/actions.rb +16 -21
- data/lib/capybara/node/base.rb +6 -6
- data/lib/capybara/node/element.rb +1 -5
- data/lib/capybara/node/finders.rb +7 -6
- data/lib/capybara/node/matchers.rb +12 -12
- data/lib/capybara/node/simple.rb +5 -1
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/current_path_query.rb +14 -4
- data/lib/capybara/queries/selector_query.rb +40 -18
- data/lib/capybara/queries/sibling_query.rb +1 -1
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +7 -1
- data/lib/capybara/rack_test/browser.rb +7 -3
- data/lib/capybara/rack_test/driver.rb +1 -0
- data/lib/capybara/rack_test/form.rb +1 -1
- data/lib/capybara/rack_test/node.rb +1 -1
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +18 -12
- data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
- data/lib/capybara/registrations/servers.rb +3 -2
- data/lib/capybara/result.rb +10 -11
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/rspec/matcher_proxies.rb +1 -1
- data/lib/capybara/rspec/matchers.rb +7 -6
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_text.rb +1 -1
- data/lib/capybara/rspec/matchers/match_style.rb +5 -0
- data/lib/capybara/selector.rb +12 -3
- data/lib/capybara/selector/builders/css_builder.rb +1 -1
- data/lib/capybara/selector/builders/xpath_builder.rb +3 -1
- data/lib/capybara/selector/definition.rb +11 -9
- data/lib/capybara/selector/definition/button.rb +26 -14
- data/lib/capybara/selector/definition/css.rb +1 -1
- data/lib/capybara/selector/definition/datalist_input.rb +1 -1
- data/lib/capybara/selector/definition/element.rb +2 -1
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/label.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/select.rb +1 -1
- data/lib/capybara/selector/definition/table.rb +1 -1
- data/lib/capybara/selector/definition/table_row.rb +2 -2
- data/lib/capybara/selector/filter_set.rb +2 -2
- data/lib/capybara/selector/selector.rb +9 -1
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
- data/lib/capybara/selenium/driver.rb +51 -7
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -11
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -11
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +3 -3
- data/lib/capybara/selenium/extensions/find.rb +4 -4
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/logger_suppressor.rb +1 -1
- data/lib/capybara/selenium/node.rb +23 -6
- data/lib/capybara/selenium/nodes/chrome_node.rb +23 -5
- data/lib/capybara/selenium/nodes/firefox_node.rb +7 -2
- data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
- data/lib/capybara/selenium/patches/action_pauser.rb +4 -1
- data/lib/capybara/selenium/patches/atoms.rb +4 -4
- data/lib/capybara/selenium/patches/logs.rb +7 -9
- data/lib/capybara/server/animation_disabler.rb +8 -3
- data/lib/capybara/server/middleware.rb +4 -2
- data/lib/capybara/session.rb +23 -14
- data/lib/capybara/session/config.rb +3 -1
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/spec/public/test.js +13 -1
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
- data/lib/capybara/spec/session/check_spec.rb +6 -0
- data/lib/capybara/spec/session/click_button_spec.rb +11 -0
- data/lib/capybara/spec/session/current_url_spec.rb +11 -1
- data/lib/capybara/spec/session/has_button_spec.rb +51 -0
- data/lib/capybara/spec/session/has_css_spec.rb +2 -1
- data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
- data/lib/capybara/spec/session/has_field_spec.rb +16 -0
- data/lib/capybara/spec/session/has_select_spec.rb +4 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_text_spec.rb +0 -11
- data/lib/capybara/spec/session/html_spec.rb +1 -1
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +29 -9
- data/lib/capybara/spec/session/refresh_spec.rb +2 -1
- data/lib/capybara/spec/session/save_page_spec.rb +4 -4
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/spec_helper.rb +12 -12
- data/lib/capybara/spec/test_app.rb +23 -21
- data/lib/capybara/spec/views/form.erb +28 -1
- data/lib/capybara/spec/views/with_animation.erb +8 -0
- data/lib/capybara/spec/views/with_dragula.erb +3 -1
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +3 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +3 -7
- data/spec/basic_node_spec.rb +9 -8
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +14 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +3 -2
- data/spec/rack_test_spec.rb +16 -5
- data/spec/result_spec.rb +1 -17
- data/spec/rspec/features_spec.rb +3 -1
- data/spec/rspec/scenarios_spec.rb +4 -0
- data/spec/rspec/shared_spec_matchers.rb +63 -51
- data/spec/rspec_spec.rb +4 -0
- data/spec/selector_spec.rb +17 -2
- data/spec/selenium_spec_chrome.rb +39 -20
- data/spec/selenium_spec_chrome_remote.rb +5 -1
- data/spec/selenium_spec_firefox.rb +15 -13
- data/spec/server_spec.rb +60 -49
- data/spec/shared_selenium_node.rb +10 -0
- data/spec/shared_selenium_session.rb +98 -7
- data/spec/spec_helper.rb +1 -1
- metadata +50 -15
- data/lib/capybara/spec/session/source_spec.rb +0 -0
data/spec/capybara_spec.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -8,7 +8,7 @@ class TestClass
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
11
|
-
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial
|
11
|
+
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation shadow_dom
|
12
12
|
] do |example|
|
13
13
|
case example.metadata[:full_description]
|
14
14
|
when /has_css\? should support case insensitive :class and :id options/
|
@@ -19,6 +19,10 @@ Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
|
19
19
|
end
|
20
20
|
|
21
21
|
RSpec.describe Capybara::DSL do
|
22
|
+
before do
|
23
|
+
Capybara.use_default_driver
|
24
|
+
end
|
25
|
+
|
22
26
|
after do
|
23
27
|
Capybara.session_name = nil
|
24
28
|
Capybara.default_driver = nil
|
@@ -238,6 +242,15 @@ RSpec.describe Capybara::DSL do
|
|
238
242
|
end
|
239
243
|
expect(Capybara.current_session).to eq(original_session)
|
240
244
|
end
|
245
|
+
|
246
|
+
it 'should pass the new session if block accepts' do
|
247
|
+
original_session = Capybara.current_session
|
248
|
+
Capybara.using_session(:administrator) do |admin_session, prev_session|
|
249
|
+
expect(admin_session).to be(Capybara.current_session)
|
250
|
+
expect(prev_session).to be(original_session)
|
251
|
+
expect(prev_session).not_to be(admin_session)
|
252
|
+
end
|
253
|
+
end
|
241
254
|
end
|
242
255
|
|
243
256
|
describe '#session_name' do
|
@@ -6,7 +6,7 @@ require 'selenium-webdriver'
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a zero exit status' do
|
8
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
9
|
-
browser = described_class.new(TestApp, options).browser
|
9
|
+
browser = described_class.new(TestApp, **options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
11
|
expect(true).to eq(true) # rubocop:disable RSpec/ExpectActual
|
12
12
|
end
|
data/spec/minitest_spec.rb
CHANGED
@@ -16,7 +16,7 @@ class MinitestTest < Minitest::Test
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_assert_text
|
19
|
-
assert_text('Form')
|
19
|
+
assert_text('Form', normalize_ws: false)
|
20
20
|
assert_no_text('Not on the page')
|
21
21
|
refute_text('Also Not on the page')
|
22
22
|
end
|
@@ -30,6 +30,7 @@ class MinitestTest < Minitest::Test
|
|
30
30
|
|
31
31
|
def test_assert_current_path
|
32
32
|
assert_current_path('/form')
|
33
|
+
assert_current_path('/form') { |url| url.query.nil? }
|
33
34
|
assert_no_current_path('/not_form')
|
34
35
|
refute_current_path('/not_form')
|
35
36
|
end
|
@@ -158,6 +159,6 @@ RSpec.describe 'capybara/minitest' do
|
|
158
159
|
reporter.start
|
159
160
|
MinitestTest.run reporter, {}
|
160
161
|
reporter.report
|
161
|
-
expect(output.string).to include('22 runs,
|
162
|
+
expect(output.string).to include('22 runs, 53 assertions, 0 failures, 0 errors, 1 skips')
|
162
163
|
end
|
163
164
|
end
|
data/spec/rack_test_spec.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
nokogumbo_required = begin
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
require 'nokogumbo'
|
6
|
+
true
|
7
|
+
rescue LoadError
|
8
|
+
false
|
9
|
+
end
|
10
10
|
|
11
11
|
module TestSessions
|
12
12
|
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
@@ -26,6 +26,8 @@ skipped_tests = %i[
|
|
26
26
|
css
|
27
27
|
scroll
|
28
28
|
spatial
|
29
|
+
html_validation
|
30
|
+
shadow_dom
|
29
31
|
]
|
30
32
|
Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
|
31
33
|
case example.metadata[:full_description]
|
@@ -37,6 +39,7 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip
|
|
37
39
|
end
|
38
40
|
|
39
41
|
RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
|
42
|
+
include Capybara::RSpecMatchers
|
40
43
|
context 'with rack test driver' do
|
41
44
|
let(:session) { TestSessions::RackTest }
|
42
45
|
|
@@ -142,6 +145,14 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
|
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
148
|
+
describe '#send_keys' do
|
149
|
+
it 'raises an UnsupportedMethodError' do
|
150
|
+
session.visit('/form')
|
151
|
+
|
152
|
+
expect { session.send_keys(:tab) }.to raise_error(Capybara::NotSupportedByDriverError)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
145
156
|
describe '#text' do
|
146
157
|
it 'should return original text content for textareas' do
|
147
158
|
session.visit('/with_html')
|
data/spec/result_spec.rb
CHANGED
@@ -190,23 +190,7 @@ RSpec.describe Capybara::Result do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
-
context 'lazy select' do
|
194
|
-
it 'is compatible' do
|
195
|
-
# This test will let us know when JRuby fixes lazy select so we can re-enable it in Result
|
196
|
-
pending 'JRuby < 9.2.8.0 has an issue with lazy enumberator evaluation' if jruby_lazy_enumerator_workaround?
|
197
|
-
eval_count = 0
|
198
|
-
enum = %w[Text1 Text2 Text3].lazy.select do
|
199
|
-
eval_count += 1
|
200
|
-
true
|
201
|
-
end
|
202
|
-
expect(eval_count).to eq 0
|
203
|
-
enum.next
|
204
|
-
sleep 1
|
205
|
-
expect(eval_count).to eq 1
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
193
|
def jruby_lazy_enumerator_workaround?
|
210
|
-
|
194
|
+
RUBY_PLATFORM == 'java'
|
211
195
|
end
|
212
196
|
end
|
data/spec/rspec/features_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable RSpec/MultipleDescribes
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
require 'capybara/rspec'
|
5
7
|
|
@@ -96,4 +98,4 @@ ffeature 'if ffeature aliases focused tag then' do # rubocop:disable RSpec/Focus
|
|
96
98
|
expect(example.metadata[:focus]).to eq true
|
97
99
|
end
|
98
100
|
end
|
99
|
-
# rubocop:enable RSpec/RepeatedExample
|
101
|
+
# rubocop:enable RSpec/RepeatedExample, RSpec/MultipleDescribes
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable RSpec/MultipleDescribes
|
4
|
+
|
3
5
|
require 'spec_helper'
|
4
6
|
require 'capybara/rspec'
|
5
7
|
|
@@ -17,3 +19,5 @@ feature 'if xscenario aliases to pending then' do
|
|
17
19
|
xscenario "this test should be 'temporarily disabled with xscenario'" do
|
18
20
|
end
|
19
21
|
end
|
22
|
+
|
23
|
+
# rubocop:enable RSpec/MultipleDescribes
|
@@ -89,29 +89,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
89
89
|
|
90
90
|
context 'on a page or node' do
|
91
91
|
before do
|
92
|
-
visit('/with_html')
|
92
|
+
session.visit('/with_html')
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'with should' do
|
96
96
|
it 'passes if has_css? returns true' do
|
97
|
-
expect(
|
97
|
+
expect(session).to have_css('h1')
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'fails if has_css? returns false' do
|
101
101
|
expect do
|
102
|
-
expect(
|
102
|
+
expect(session).to have_css('h1#doesnotexist')
|
103
103
|
end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
context 'with should_not' do
|
108
108
|
it 'passes if has_no_css? returns true' do
|
109
|
-
expect(
|
109
|
+
expect(session).not_to have_css('h1#doesnotexist')
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'fails if has_no_css? returns false' do
|
113
113
|
expect do
|
114
|
-
expect(
|
114
|
+
expect(session).not_to have_css('h1')
|
115
115
|
end.to raise_error(/expected not to find visible css "h1"/)
|
116
116
|
end
|
117
117
|
end
|
@@ -158,29 +158,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
158
158
|
|
159
159
|
context 'on a page or node' do
|
160
160
|
before do
|
161
|
-
visit('/with_html')
|
161
|
+
session.visit('/with_html')
|
162
162
|
end
|
163
163
|
|
164
164
|
context 'with should' do
|
165
165
|
it 'passes if has_xpath? returns true' do
|
166
|
-
expect(
|
166
|
+
expect(session).to have_xpath('//h1')
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'fails if has_xpath? returns false' do
|
170
170
|
expect do
|
171
|
-
expect(
|
171
|
+
expect(session).to have_xpath("//h1[@id='doesnotexist']")
|
172
172
|
end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
176
|
context 'with should_not' do
|
177
177
|
it 'passes if has_no_xpath? returns true' do
|
178
|
-
expect(
|
178
|
+
expect(session).not_to have_xpath('//h1[@id="doesnotexist"]')
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'fails if has_no_xpath? returns false' do
|
182
182
|
expect do
|
183
|
-
expect(
|
183
|
+
expect(session).not_to have_xpath('//h1')
|
184
184
|
end.to raise_error(%r{expected not to find visible xpath "//h1"})
|
185
185
|
end
|
186
186
|
end
|
@@ -222,35 +222,35 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
222
222
|
|
223
223
|
context 'on a page or node' do
|
224
224
|
before do
|
225
|
-
visit('/with_html')
|
225
|
+
session.visit('/with_html')
|
226
226
|
end
|
227
227
|
|
228
228
|
context 'with should' do
|
229
229
|
it 'passes if has_selector? returns true' do
|
230
|
-
expect(
|
230
|
+
expect(session).to have_selector('//h1', text: 'test')
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'fails if has_selector? returns false' do
|
234
234
|
expect do
|
235
|
-
expect(
|
235
|
+
expect(session).to have_selector("//h1[@id='doesnotexist']")
|
236
236
|
end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'includes text in error message' do
|
240
240
|
expect do
|
241
|
-
expect(
|
241
|
+
expect(session).to have_selector('//h1', text: 'wrong text')
|
242
242
|
end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
246
|
context 'with should_not' do
|
247
247
|
it 'passes if has_no_css? returns true' do
|
248
|
-
expect(
|
248
|
+
expect(session).not_to have_selector(:css, 'h1#doesnotexist')
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'fails if has_no_selector? returns false' do
|
252
252
|
expect do
|
253
|
-
expect(
|
253
|
+
expect(session).not_to have_selector(:css, 'h1', text: 'test')
|
254
254
|
end.to raise_error(/expected not to find visible css "h1" with text "test"/)
|
255
255
|
end
|
256
256
|
end
|
@@ -265,7 +265,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
265
265
|
|
266
266
|
describe 'have_content matcher' do
|
267
267
|
it 'gives proper description' do
|
268
|
-
expect(have_content('Text').description).to eq('text "Text"')
|
268
|
+
expect(have_content('Text').description).to eq('have text "Text"')
|
269
269
|
end
|
270
270
|
|
271
271
|
context 'on a string' do
|
@@ -304,21 +304,21 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
304
304
|
|
305
305
|
context 'on a page or node' do
|
306
306
|
before do
|
307
|
-
visit('/with_html')
|
307
|
+
session.visit('/with_html')
|
308
308
|
end
|
309
309
|
|
310
310
|
context 'with should' do
|
311
311
|
it 'passes if has_content? returns true' do
|
312
|
-
expect(
|
312
|
+
expect(session).to have_content('This is a test')
|
313
313
|
end
|
314
314
|
|
315
315
|
it 'passes if has_content? returns true using regexp' do
|
316
|
-
expect(
|
316
|
+
expect(session).to have_content(/test/)
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'fails if has_content? returns false' do
|
320
320
|
expect do
|
321
|
-
expect(
|
321
|
+
expect(session).to have_content('No such Text')
|
322
322
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
323
323
|
end
|
324
324
|
|
@@ -329,7 +329,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
329
329
|
|
330
330
|
it 'fails if has_content? returns false' do
|
331
331
|
expect do
|
332
|
-
expect(
|
332
|
+
expect(session).to have_content('No such Text')
|
333
333
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
334
334
|
end
|
335
335
|
end
|
@@ -337,14 +337,26 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
337
337
|
|
338
338
|
context 'with should_not' do
|
339
339
|
it 'passes if has_no_content? returns true' do
|
340
|
-
expect(
|
340
|
+
expect(session).not_to have_content('No such Text')
|
341
341
|
end
|
342
342
|
|
343
343
|
it 'fails if has_no_content? returns false' do
|
344
344
|
expect do
|
345
|
-
expect(
|
345
|
+
expect(session).not_to have_content('This is a test')
|
346
346
|
end.to raise_error(/expected not to find text "This is a test"/)
|
347
347
|
end
|
348
|
+
|
349
|
+
it 'not_to have_content behaves the same as to have_no_content' do
|
350
|
+
Capybara.using_wait_time(5) do
|
351
|
+
expect(session).to have_content('This is a test')
|
352
|
+
start = Time.now
|
353
|
+
expect(session).to have_no_content('No such Text')
|
354
|
+
to_time = Time.now
|
355
|
+
expect(session).not_to have_content('No such Text')
|
356
|
+
not_to_time = Time.now
|
357
|
+
expect(not_to_time - to_time).to be_within(0.5).of(to_time - start)
|
358
|
+
end
|
359
|
+
end
|
348
360
|
end
|
349
361
|
end
|
350
362
|
|
@@ -357,7 +369,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
357
369
|
|
358
370
|
describe 'have_text matcher' do
|
359
371
|
it 'gives proper description' do
|
360
|
-
expect(have_text('Text').description).to eq('text "Text"')
|
372
|
+
expect(have_text('Text').description).to eq('have text "Text"')
|
361
373
|
end
|
362
374
|
|
363
375
|
context 'on a string' do
|
@@ -432,30 +444,30 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
432
444
|
|
433
445
|
context 'on a page or node' do
|
434
446
|
before do
|
435
|
-
visit('/with_html')
|
447
|
+
session.visit('/with_html')
|
436
448
|
end
|
437
449
|
|
438
450
|
context 'with should' do
|
439
451
|
it 'passes if has_text? returns true' do
|
440
|
-
expect(
|
452
|
+
expect(session).to have_text('This is a test')
|
441
453
|
end
|
442
454
|
|
443
455
|
it 'passes if has_text? returns true using regexp' do
|
444
|
-
expect(
|
456
|
+
expect(session).to have_text(/test/)
|
445
457
|
end
|
446
458
|
|
447
459
|
it 'can check for all text' do
|
448
|
-
expect(
|
460
|
+
expect(session).to have_text(:all, 'Some of this text is hidden!')
|
449
461
|
end
|
450
462
|
|
451
463
|
it 'can check for visible text' do
|
452
|
-
expect(
|
453
|
-
expect(
|
464
|
+
expect(session).to have_text(:visible, 'Some of this text is')
|
465
|
+
expect(session).not_to have_text(:visible, 'Some of this text is hidden!')
|
454
466
|
end
|
455
467
|
|
456
468
|
it 'fails if has_text? returns false' do
|
457
469
|
expect do
|
458
|
-
expect(
|
470
|
+
expect(session).to have_text('No such Text')
|
459
471
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
460
472
|
end
|
461
473
|
|
@@ -466,7 +478,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
466
478
|
|
467
479
|
it 'fails if has_text? returns false' do
|
468
480
|
expect do
|
469
|
-
expect(
|
481
|
+
expect(session).to have_text('No such Text')
|
470
482
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
471
483
|
end
|
472
484
|
end
|
@@ -474,12 +486,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
474
486
|
|
475
487
|
context 'with should_not' do
|
476
488
|
it 'passes if has_no_text? returns true' do
|
477
|
-
expect(
|
489
|
+
expect(session).not_to have_text('No such Text')
|
478
490
|
end
|
479
491
|
|
480
492
|
it 'fails if has_no_text? returns false' do
|
481
493
|
expect do
|
482
|
-
expect(
|
494
|
+
expect(session).not_to have_text('This is a test')
|
483
495
|
end.to raise_error(/expected not to find text "This is a test"/)
|
484
496
|
end
|
485
497
|
end
|
@@ -542,15 +554,15 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
542
554
|
|
543
555
|
context 'on a page or node' do
|
544
556
|
it 'passes if there is such a title' do
|
545
|
-
visit('/with_js')
|
546
|
-
expect(
|
557
|
+
session.visit('/with_js')
|
558
|
+
expect(session).to have_title('with_js')
|
547
559
|
end
|
548
560
|
|
549
561
|
it 'fails if there is no such title' do
|
550
|
-
visit('/with_js')
|
562
|
+
session.visit('/with_js')
|
551
563
|
expect do
|
552
|
-
expect(
|
553
|
-
end.to raise_error(
|
564
|
+
expect(session).to have_title('No such title')
|
565
|
+
end.to raise_error(/ to include "No such title"/)
|
554
566
|
end
|
555
567
|
|
556
568
|
context 'with wait' do
|
@@ -560,14 +572,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
560
572
|
|
561
573
|
it 'waits if wait time is more than timeout' do
|
562
574
|
session.click_link('Change title')
|
563
|
-
using_wait_time 0 do
|
575
|
+
session.using_wait_time 0 do
|
564
576
|
expect(session).to have_title('changed title', wait: 2)
|
565
577
|
end
|
566
578
|
end
|
567
579
|
|
568
580
|
it "doesn't wait if wait time is less than timeout" do
|
569
581
|
session.click_link('Change title')
|
570
|
-
using_wait_time 3 do
|
582
|
+
session.using_wait_time 3 do
|
571
583
|
expect(session).not_to have_title('changed title', wait: 0)
|
572
584
|
end
|
573
585
|
end
|
@@ -586,15 +598,15 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
586
598
|
|
587
599
|
context 'on a page or node' do
|
588
600
|
it 'passes if there is such a current path' do
|
589
|
-
visit('/with_js')
|
590
|
-
expect(
|
601
|
+
session.visit('/with_js')
|
602
|
+
expect(session).to have_current_path('/with_js')
|
591
603
|
end
|
592
604
|
|
593
605
|
it 'fails if there is no such current_path' do
|
594
606
|
visit('/with_js')
|
595
607
|
expect do
|
596
|
-
expect(
|
597
|
-
end.to raise_error(
|
608
|
+
expect(session).to have_current_path('/not_with_js')
|
609
|
+
end.to raise_error(%r{to equal "/not_with_js"})
|
598
610
|
end
|
599
611
|
|
600
612
|
context 'with wait' do
|
@@ -604,14 +616,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
604
616
|
|
605
617
|
it 'waits if wait time is more than timeout' do
|
606
618
|
session.click_link('Change page')
|
607
|
-
using_wait_time 0 do
|
619
|
+
session.using_wait_time 0 do
|
608
620
|
expect(session).to have_current_path('/with_html', wait: 2)
|
609
621
|
end
|
610
622
|
end
|
611
623
|
|
612
624
|
it "doesn't wait if wait time is less than timeout" do
|
613
625
|
session.click_link('Change page')
|
614
|
-
using_wait_time 0 do
|
626
|
+
session.using_wait_time 0 do
|
615
627
|
expect(session).not_to have_current_path('/with_html')
|
616
628
|
end
|
617
629
|
end
|
@@ -619,8 +631,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
619
631
|
end
|
620
632
|
|
621
633
|
it 'supports compounding' do
|
622
|
-
visit('/with_html')
|
623
|
-
expect(
|
634
|
+
session.visit('/with_html')
|
635
|
+
expect(session).to have_current_path('/not_with_html').or have_current_path('/with_html')
|
624
636
|
end
|
625
637
|
end
|
626
638
|
|
@@ -859,7 +871,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
859
871
|
|
860
872
|
describe '#and' do
|
861
873
|
it "should run 'concurrently'" do
|
862
|
-
|
874
|
+
session.using_wait_time(2) do
|
863
875
|
matcher = have_text('this is not there').and have_text('neither is this')
|
864
876
|
expect(Benchmark.realtime do
|
865
877
|
expect do
|