capybara 3.6.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +16 -0
  3. data/README.md +5 -1
  4. data/lib/capybara.rb +2 -0
  5. data/lib/capybara/minitest/spec.rb +1 -1
  6. data/lib/capybara/node/actions.rb +34 -25
  7. data/lib/capybara/node/base.rb +15 -17
  8. data/lib/capybara/node/document_matchers.rb +1 -3
  9. data/lib/capybara/node/element.rb +11 -12
  10. data/lib/capybara/node/finders.rb +2 -1
  11. data/lib/capybara/node/simple.rb +13 -6
  12. data/lib/capybara/queries/base_query.rb +4 -4
  13. data/lib/capybara/queries/selector_query.rb +119 -94
  14. data/lib/capybara/queries/text_query.rb +2 -1
  15. data/lib/capybara/rack_test/form.rb +4 -4
  16. data/lib/capybara/rack_test/node.rb +5 -5
  17. data/lib/capybara/result.rb +23 -32
  18. data/lib/capybara/rspec/compound.rb +1 -1
  19. data/lib/capybara/rspec/matchers.rb +63 -61
  20. data/lib/capybara/selector.rb +28 -10
  21. data/lib/capybara/selector/css.rb +17 -17
  22. data/lib/capybara/selector/filter_set.rb +9 -9
  23. data/lib/capybara/selector/selector.rb +3 -4
  24. data/lib/capybara/selenium/driver.rb +73 -95
  25. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +4 -4
  26. data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +9 -0
  27. data/lib/capybara/selenium/node.rb +127 -67
  28. data/lib/capybara/selenium/nodes/chrome_node.rb +3 -3
  29. data/lib/capybara/selenium/nodes/marionette_node.rb +14 -8
  30. data/lib/capybara/server.rb +2 -2
  31. data/lib/capybara/server/animation_disabler.rb +17 -3
  32. data/lib/capybara/server/middleware.rb +8 -4
  33. data/lib/capybara/session.rb +43 -37
  34. data/lib/capybara/session/config.rb +8 -6
  35. data/lib/capybara/spec/session/assert_text_spec.rb +14 -0
  36. data/lib/capybara/spec/session/attach_file_spec.rb +7 -0
  37. data/lib/capybara/spec/session/check_spec.rb +21 -0
  38. data/lib/capybara/spec/session/choose_spec.rb +15 -1
  39. data/lib/capybara/spec/session/fill_in_spec.rb +7 -0
  40. data/lib/capybara/spec/session/find_spec.rb +2 -1
  41. data/lib/capybara/spec/session/has_selector_spec.rb +18 -0
  42. data/lib/capybara/spec/session/has_text_spec.rb +14 -0
  43. data/lib/capybara/spec/session/node_spec.rb +2 -1
  44. data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
  45. data/lib/capybara/spec/session/text_spec.rb +2 -1
  46. data/lib/capybara/spec/session/title_spec.rb +2 -1
  47. data/lib/capybara/spec/session/uncheck_spec.rb +8 -0
  48. data/lib/capybara/spec/session/within_spec.rb +2 -1
  49. data/lib/capybara/spec/spec_helper.rb +1 -32
  50. data/lib/capybara/spec/views/with_js.erb +3 -4
  51. data/lib/capybara/version.rb +1 -1
  52. data/spec/minitest_spec.rb +4 -0
  53. data/spec/minitest_spec_spec.rb +4 -0
  54. data/spec/rack_test_spec.rb +4 -4
  55. data/spec/rspec/shared_spec_matchers.rb +4 -2
  56. data/spec/selector_spec.rb +15 -1
  57. data/spec/selenium_spec_chrome.rb +1 -6
  58. data/spec/selenium_spec_chrome_remote.rb +1 -1
  59. data/spec/selenium_spec_firefox_remote.rb +2 -5
  60. data/spec/selenium_spec_ie.rb +41 -4
  61. data/spec/selenium_spec_marionette.rb +1 -25
  62. data/spec/shared_selenium_session.rb +74 -16
  63. data/spec/spec_helper.rb +41 -0
  64. metadata +2 -2
@@ -45,11 +45,12 @@ Capybara::SpecHelper.spec '#text' do
45
45
  context 'with css as default selector' do
46
46
  before { Capybara.default_selector = :css }
47
47
 
48
+ after { Capybara.default_selector = :xpath }
49
+
48
50
  it 'should print the text of the page' do
49
51
  @session.visit('/with_simple_html')
50
52
  expect(@session.text).to eq('Bar')
51
53
  end
52
- after { Capybara.default_selector = :xpath }
53
54
  end
54
55
 
55
56
  it 'should be correctly normalized when visible' do
@@ -9,11 +9,12 @@ Capybara::SpecHelper.spec '#title' do
9
9
  context 'with css as default selector' do
10
10
  before { Capybara.default_selector = :css }
11
11
 
12
+ after { Capybara.default_selector = :xpath }
13
+
12
14
  it 'should get the title of the page' do
13
15
  @session.visit('/with_title')
14
16
  expect(@session.title).to eq('Test Title')
15
17
  end
16
- after { Capybara.default_selector = :xpath }
17
18
  end
18
19
 
19
20
  context 'within iframe', requires: [:frames] do
@@ -26,6 +26,14 @@ Capybara::SpecHelper.spec '#uncheck' do
26
26
  expect(extract_results(@session)['pets']).not_to include('hamster')
27
27
  end
28
28
 
29
+ it 'should be able to uncheck itself if no locator specified' do
30
+ cb = @session.find(:id, 'form_pets_hamster')
31
+ cb.uncheck
32
+ @session.click_button('awesome')
33
+ expect(extract_results(@session)['pets']).to include('dog')
34
+ expect(extract_results(@session)['pets']).not_to include('hamster')
35
+ end
36
+
29
37
  it 'casts to string' do
30
38
  @session.uncheck(:form_pets_hamster)
31
39
  @session.click_button('awesome')
@@ -60,13 +60,14 @@ Capybara::SpecHelper.spec '#within' do
60
60
  context 'with the default selector set to CSS' do
61
61
  before { Capybara.default_selector = :css }
62
62
 
63
+ after { Capybara.default_selector = :xpath }
64
+
63
65
  it 'should use CSS' do
64
66
  @session.within('#for_bar li', text: 'With Simple HTML') do
65
67
  @session.click_link('Go')
66
68
  end
67
69
  expect(@session).to have_content('Bar')
68
70
  end
69
- after { Capybara.default_selector = :xpath }
70
71
  end
71
72
 
72
73
  context 'with nested scopes' do
@@ -35,6 +35,7 @@ module Capybara
35
35
  Capybara.disable_animation = false
36
36
  Capybara.test_id = nil
37
37
  Capybara.predicates_wait = true
38
+ Capybara.default_normalize_ws = false
38
39
  reset_threadsafe
39
40
  end
40
41
 
@@ -118,38 +119,6 @@ module Capybara
118
119
  expect(session).to have_xpath("//pre[@id='results']")
119
120
  YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
120
121
  end
121
-
122
- def marionette?(session)
123
- session.respond_to?(:driver) && session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
124
- end
125
-
126
- def marionette_lt?(version, session)
127
- marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
128
- end
129
-
130
- def marionette_gte?(version, session)
131
- marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
132
- end
133
-
134
- def chrome?(session)
135
- session.respond_to?(:driver) && session.driver.respond_to?(:chrome?, true) && session.driver.send(:chrome?)
136
- end
137
-
138
- def chrome_lt?(version, session)
139
- chrome?(session) && (session.driver.browser.capabilities[:version].to_f < version)
140
- end
141
-
142
- def chrome_gte?(version, session)
143
- chrome?(session) && (session.driver.browser.capabilities[:version].to_f >= version)
144
- end
145
-
146
- def edge?(session)
147
- session.respond_to?(:driver) && session.driver.respond_to?(:edge?, true) && session.driver.send(:edge?)
148
- end
149
-
150
- def ie?(session)
151
- session.respond_to?(:driver) && session.driver.respond_to?(:ie?, true) && session.driver.send(:ie?)
152
- end
153
122
  end
154
123
  end
155
124
 
@@ -18,7 +18,9 @@
18
18
  <div id="drop">
19
19
  <p>It should be dropped here.</p>
20
20
  </div>
21
-
21
+ <div id="drop_scroll">
22
+ <p>It should be dropped here.</p>
23
+ </div>
22
24
  <div id="drop_html5_scroll" class="drop">
23
25
  <p>It should be dropped here.</p>
24
26
  </div>
@@ -142,9 +144,6 @@
142
144
  <div id="drag_scroll">
143
145
  <p>This is a draggable element.</p>
144
146
  </div>
145
- <div id="drop_scroll">
146
- <p>It should be dropped here.</p>
147
- </div>
148
147
  <div id="drag_html5_scroll" draggable="true">
149
148
  <p>This is an HTML5 draggable element.</p>
150
149
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Capybara
4
- VERSION = '3.6.0'
4
+ VERSION = '3.7.0'
5
5
  end
@@ -134,6 +134,10 @@ RSpec.describe 'capybara/minitest' do
134
134
  Capybara.app = TestApp
135
135
  end
136
136
 
137
+ after do
138
+ Capybara.use_default_driver
139
+ end
140
+
137
141
  it 'should support minitest' do
138
142
  output = StringIO.new
139
143
  reporter = Minitest::SummaryReporter.new(output)
@@ -130,6 +130,10 @@ RSpec.describe 'capybara/minitest/spec' do
130
130
  Capybara.app = TestApp
131
131
  end
132
132
 
133
+ after do
134
+ Capybara.use_default_driver
135
+ end
136
+
133
137
  it 'should support minitest spec' do
134
138
  output = StringIO.new
135
139
  reporter = Minitest::SummaryReporter.new(output)
@@ -40,6 +40,10 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
40
40
  end
41
41
 
42
42
  describe '#click_link' do
43
+ after do
44
+ @session.driver.options[:respect_data_method] = false
45
+ end
46
+
43
47
  it 'should use data-method if option is true' do
44
48
  @session.driver.options[:respect_data_method] = true
45
49
  @session.visit '/with_html'
@@ -60,10 +64,6 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
60
64
  @session.click_link 'A link with capitalized data-method'
61
65
  expect(@session.html).to include('The requested object was deleted')
62
66
  end
63
-
64
- after do
65
- @session.driver.options[:respect_data_method] = false
66
- end
67
67
  end
68
68
 
69
69
  describe '#fill_in' do
@@ -325,12 +325,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
325
325
  context 'with default selector CSS' do
326
326
  before { Capybara.default_selector = :css }
327
327
 
328
+ after { Capybara.default_selector = :xpath }
329
+
328
330
  it 'fails if has_content? returns false' do
329
331
  expect do
330
332
  expect(page).to have_content('No such Text')
331
333
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
332
334
  end
333
- after { Capybara.default_selector = :xpath }
334
335
  end
335
336
  end
336
337
 
@@ -461,12 +462,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
461
462
  context 'with default selector CSS' do
462
463
  before { Capybara.default_selector = :css }
463
464
 
465
+ after { Capybara.default_selector = :xpath }
466
+
464
467
  it 'fails if has_text? returns false' do
465
468
  expect do
466
469
  expect(page).to have_text('No such Text')
467
470
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
468
471
  end
469
- after { Capybara.default_selector = :xpath }
470
472
  end
471
473
  end
472
474
 
@@ -261,11 +261,25 @@ RSpec.describe Capybara do
261
261
  expect { string.all(:element, 'input', type: 'submit', count: 1) }.not_to raise_error
262
262
  end
263
263
 
264
+ it 'works without element type' do
265
+ expect(string.find(:element, type: 'submit').value).to eq 'click me'
266
+ end
267
+
268
+ it 'validates attribute presence when true' do
269
+ expect(string.find(:element, name: true)[:id]).to eq 'my_text_input'
270
+ end
271
+
272
+ it 'validates attribute absence when false' do
273
+ expect(string.find(:element, 'option', disabled: false, selected: false).value).to eq 'a'
274
+ end
275
+
264
276
  it 'includes wildcarded keys in description' do
265
- expect { string.find(:element, 'input', not_there: 'bad', count: 1) }
277
+ expect { string.find(:element, 'input', not_there: 'bad', presence: true, absence: false, count: 1) }
266
278
  .to(raise_error do |e|
267
279
  expect(e).to be_a(Capybara::ElementNotFound)
268
280
  expect(e.message).to include 'not_there => bad'
281
+ expect(e.message).to include 'with presence attribute'
282
+ expect(e.message).to include 'without absence attribute'
269
283
  expect(e.message).not_to include 'count 1'
270
284
  end)
271
285
  end
@@ -45,12 +45,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLE
45
45
 
46
46
  $stdout.puts `#{Selenium::WebDriver::Chrome.driver_path} --version` if ENV['CI']
47
47
 
48
- Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests do |example|
49
- case example.metadata[:description]
50
- when /should fetch a response when sequentially visiting same destination with a target/
51
- skip 'Chrome/chromedriver has an issue visiting URL with target after visiting same URL without target' if chrome_lt?(65.0, @session)
52
- end
53
- end
48
+ Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests
54
49
 
55
50
  RSpec.describe 'Capybara::Session with chrome' do
56
51
  include Capybara::SpecHelper
@@ -77,6 +77,6 @@ RSpec.describe 'Capybara::Session with remote Chrome' do
77
77
  include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_REMOTE_DRIVER
78
78
 
79
79
  it 'is considered to be chrome' do
80
- expect(session.driver.send(:chrome?)).to be_truthy
80
+ expect(session.driver.browser.browser).to eq :chrome
81
81
  end
82
82
  end
@@ -64,10 +64,8 @@ Capybara::SpecHelper.run_specs TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVE
64
64
  pending "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session)
65
65
  when /^Capybara::Session selenium node #double_click/
66
66
  pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
67
- when 'Capybara::Session selenium_firefox_remote #refresh it reposts'
68
- skip 'Firefox insists on prompting without providing a way to suppress'
69
67
  when 'Capybara::Session selenium_firefox_remote #accept_prompt should accept the prompt with a blank response when there is a default'
70
- pending "Geckodriver doesn't set a blank response currently"
68
+ pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if marionette_lt?(63, @session)
71
69
  when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once for each set of files uploaded',
72
70
  'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
73
71
  pending 'Due to having to work around selenium remote lack of multiple file upload support the change event count is off'
@@ -80,7 +78,6 @@ RSpec.describe 'Capybara::Session with remote firefox' do
80
78
  include_examples Capybara::RSpecMatchers, TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVER
81
79
 
82
80
  it 'is considered to be firefox' do
83
- expect(session.driver.send(:firefox?)).to be_truthy
84
- expect(session.driver.send(:marionette?)).to be_truthy
81
+ expect(session.driver.browser.browser).to eq :firefox
85
82
  end
86
83
  end
@@ -7,10 +7,13 @@ require 'rspec/shared_spec_matchers'
7
7
 
8
8
  Capybara.register_driver :selenium_ie do |app|
9
9
  # ::Selenium::WebDriver.logger.level = "debug"
10
+ options = ::Selenium::WebDriver::IE::Options.new
11
+ options.require_window_focus = true
10
12
  Capybara::Selenium::Driver.new(
11
13
  app,
12
14
  browser: :ie,
13
- desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.ie('requireWindowFocus': true)
15
+ desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.ie,
16
+ options: options
14
17
  )
15
18
  end
16
19
 
@@ -18,6 +21,8 @@ module TestSessions
18
21
  SeleniumIE = Capybara::Session.new(:selenium_ie, TestApp)
19
22
  end
20
23
 
24
+ TestSessions::SeleniumIE.current_window.resize_to(800, 500)
25
+
21
26
  skipped_tests = %i[response_headers status_code trigger modals hover form_attribute windows]
22
27
 
23
28
  $stdout.puts `#{Selenium::WebDriver::IE.driver_path} --version` if ENV['CI']
@@ -27,18 +32,50 @@ TestSessions::SeleniumIE.current_window.resize_to(1600, 1200)
27
32
  Capybara::SpecHelper.run_specs TestSessions::SeleniumIE, 'selenium', capybara_skip: skipped_tests do |example|
28
33
  case example.metadata[:full_description]
29
34
  when /#refresh it reposts$/
30
- skip 'Firefox and Edge insist on prompting without providing a way to suppress'
35
+ skip 'IE insists on prompting without providing a way to suppress'
31
36
  when /#click_link can download a file$/
32
37
  skip 'Not sure how to configure IE for automatic downloading'
33
38
  when /#fill_in with Date /
34
39
  pending "IE 11 doesn't support date input types"
35
40
  when /#click_link_or_button with :disabled option happily clicks on links which incorrectly have the disabled attribute$/
36
- pending 'IE 11 obeys non-standard disabled attribute on anchor tag'
41
+ skip 'IE 11 obeys non-standard disabled attribute on anchor tag'
42
+ when /#right_click should allow modifiers$/
43
+ skip "Windows can't :meta click because :meta triggers start menu"
44
+ when /#click should allow multiple modifiers$/
45
+ skip "Windows can't :meta click because :meta triggers start menu"
46
+ when /#double_click should allow multiple modifiers$/
47
+ skip "Windows can't :alt double click due to being properties shortcut"
48
+ when /via clicking the wrapping label if possible$/
49
+ pending 'IEDriver has an issue with the click location of elements with multiple children if the first child is a text node and the page is scrolled'
37
50
  end
38
51
  end
39
52
 
40
- RSpec.describe 'Capybara::Session with Internet Explorer', capybara_skip: skipped_tests do
53
+ RSpec.describe 'Capybara::Session with Internet Explorer', capybara_skip: skipped_tests do # rubocop:disable RSpec/MultipleDescribes
41
54
  include Capybara::SpecHelper
42
55
  include_examples 'Capybara::Session', TestSessions::SeleniumIE, :selenium_ie
43
56
  include_examples Capybara::RSpecMatchers, TestSessions::SeleniumIE, :selenium_ie
44
57
  end
58
+
59
+ RSpec.describe Capybara::Selenium::Node do
60
+ it '#right_click should allow modifiers' do
61
+ session = TestSessions::SeleniumIE
62
+ session.visit('/with_js')
63
+ session.find(:css, '#click-test').right_click(:control)
64
+ expect(session).to have_link('Has been control right clicked')
65
+ end
66
+
67
+ it '#click should allow multiple modifiers' do
68
+ session = TestSessions::SeleniumIE
69
+ session.visit('with_js')
70
+ # IE triggers system behavior with :meta so can't use those here
71
+ session.find(:css, '#click-test').click(:ctrl, :shift, :alt)
72
+ expect(session).to have_link('Has been alt control shift clicked')
73
+ end
74
+
75
+ it '#double_click should allow modifiers' do
76
+ session = TestSessions::SeleniumIE
77
+ session.visit('/with_js')
78
+ session.find(:css, '#click-test').double_click(:shift)
79
+ expect(session).to have_link('Has been shift double clicked')
80
+ end
81
+ end
@@ -54,10 +54,8 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, 'selenium', cap
54
54
  pending "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session)
55
55
  when /^Capybara::Session selenium node #double_click/
56
56
  pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
57
- when 'Capybara::Session selenium #refresh it reposts'
58
- skip 'Firefox insists on prompting without providing a way to suppress'
59
57
  when 'Capybara::Session selenium #accept_prompt should accept the prompt with a blank response when there is a default'
60
- pending "Geckodriver doesn't set a blank response currently"
58
+ pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if marionette_lt?(63, @session)
61
59
  when 'Capybara::Session selenium #attach_file with multipart form should fire change once for each set of files uploaded'
62
60
  pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
63
61
  'if files are already set'
@@ -145,28 +143,6 @@ RSpec.describe Capybara::Selenium::Driver do
145
143
  end
146
144
  end
147
145
  end
148
-
149
- context '#refresh' do
150
- def extract_results(session)
151
- expect(session).to have_xpath("//pre[@id='results']")
152
- YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
153
- end
154
-
155
- it 'can repost by accepting confirm' do
156
- @session = TestSessions::SeleniumMarionette
157
- @session.visit('/form')
158
- @session.select('Sweden', from: 'form_region')
159
- @session.click_button('awesome')
160
- sleep 1
161
- expect do
162
- @session.accept_confirm(wait: 0.1) do
163
- @session.refresh
164
- sleep 2
165
- end
166
- sleep 1
167
- end.to change { extract_results(@session)['post_count'] }.by(1)
168
- end
169
- end
170
146
  end
171
147
 
172
148
  RSpec.describe Capybara::Selenium::Node do
@@ -305,7 +305,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
305
305
  expect(session).not_to have_xpath('//div[contains(., "HTML5 Dropped drag_html5")]')
306
306
  end
307
307
 
308
- it 'should HTML6 drag and drop when scrolling needed' do
308
+ it 'should HTML5 drag and drop when scrolling needed' do
309
309
  pending "Firefox < 62 doesn't support a DataTransfer constuctor" if marionette_lt?(62.0, session)
310
310
  session.visit('/with_js')
311
311
  element = session.find('//div[@id="drag_html5_scroll"]')
@@ -323,26 +323,84 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
323
323
  end
324
324
  end
325
325
 
326
- context 'AnimationDisabler' do
327
- before(:context) do # rubocop:disable RSpec/BeforeAfterAll
328
- Capybara.disable_animation = true
329
- @animation_session = Capybara::Session.new(session.mode, TestApp.new)
330
- end
326
+ describe 'Capybara#disable_animation' do
327
+ context 'when set to `true`' do
328
+ before(:context) do # rubocop:disable RSpec/BeforeAfterAll
329
+ # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
330
+ # it doesn't affect any of these tests because the settings are applied per-session
331
+ Capybara.disable_animation = true
332
+ @animation_session = Capybara::Session.new(session.mode, TestApp.new)
333
+ end
334
+
335
+ after(:context) do # rubocop:disable RSpec/BeforeAfterAll
336
+ @animation_session = nil
337
+ end
338
+
339
+ it 'should disable CSS transitions' do
340
+ @animation_session.visit('with_animation')
341
+ @animation_session.click_link('transition me away')
342
+ expect(@animation_session).to have_no_link('transition me away', wait: 0.5)
343
+ end
331
344
 
332
- after(:context) do # rubocop:disable RSpec/BeforeAfterAll
333
- Capybara.disable_animation = false
345
+ it 'should disable CSS animations' do
346
+ @animation_session.visit('with_animation')
347
+ @animation_session.click_link('animate me away')
348
+ expect(@animation_session).to have_no_link('animate me away', wait: 0.5)
349
+ end
334
350
  end
335
351
 
336
- it 'should disable CSS transitions' do
337
- @animation_session.visit('with_animation')
338
- @animation_session.click_link('transition me away')
339
- expect(@animation_session).to have_no_link('transition me away', wait: 0.5)
352
+ context 'if we pass in css that matches elements' do
353
+ before(:context) do # rubocop:disable RSpec/BeforeAfterAll
354
+ # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
355
+ # it doesn't affect any of these tests because the settings are applied per-session
356
+ Capybara.disable_animation = '#with_animation a'
357
+ @animation_session_with_matching_css = Capybara::Session.new(session.mode, TestApp.new)
358
+ end
359
+
360
+ after(:context) do # rubocop:disable RSpec/BeforeAfterAll
361
+ @animation_session_with_matching_css = nil
362
+ end
363
+
364
+ it 'should disable CSS transitions' do
365
+ @animation_session_with_matching_css.visit('with_animation')
366
+ @animation_session_with_matching_css.click_link('transition me away')
367
+ expect(@animation_session_with_matching_css).to have_no_link('transition me away', wait: 0.5)
368
+ end
369
+
370
+ it 'should disable CSS animations' do
371
+ @animation_session_with_matching_css.visit('with_animation')
372
+ @animation_session_with_matching_css.click_link('animate me away')
373
+ expect(@animation_session_with_matching_css).to have_no_link('animate me away', wait: 0.5)
374
+ end
340
375
  end
341
376
 
342
- it 'should disable CSS animations' do
343
- @animation_session.visit('with_animation')
344
- @animation_session.click_link('animate me away')
345
- expect(@animation_session).to have_no_link('animate me away', wait: 0.5)
377
+ context 'if we pass in css that does not match elements' do
378
+ before(:context) do # rubocop:disable RSpec/BeforeAfterAll
379
+ # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
380
+ # it doesn't affect any of these tests because the settings are applied per-session
381
+ Capybara.disable_animation = '.this-class-matches-nothing'
382
+ @animation_session_without_matching_css = Capybara::Session.new(session.mode, TestApp.new)
383
+ end
384
+
385
+ after(:context) do # rubocop:disable RSpec/BeforeAfterAll
386
+ @animation_session_without_matching_css = nil
387
+ end
388
+
389
+ it 'should not disable CSS transitions' do
390
+ @animation_session_without_matching_css.visit('with_animation')
391
+ @animation_session_without_matching_css.click_link('transition me away')
392
+ sleep 0.5 # Wait long enough for click to have been processed
393
+ expect(@animation_session_without_matching_css).to have_link('transition me away', wait: false)
394
+ expect(@animation_session_without_matching_css).to have_no_link('transition me away', wait: 5)
395
+ end
396
+
397
+ it 'should not disable CSS animations' do
398
+ @animation_session_without_matching_css.visit('with_animation')
399
+ @animation_session_without_matching_css.click_link('animate me away')
400
+ sleep 0.5 # Wait long enough for click to have been processed
401
+ expect(@animation_session_without_matching_css).to have_link('animate me away', wait: false)
402
+ expect(@animation_session_without_matching_css).to have_no_link('animate me away', wait: 5)
403
+ end
346
404
  end
347
405
  end
348
406
  end