capybara 3.3.1 → 3.4.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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +16 -0
  3. data/README.md +5 -7
  4. data/lib/capybara.rb +7 -6
  5. data/lib/capybara/config.rb +1 -1
  6. data/lib/capybara/dsl.rb +2 -2
  7. data/lib/capybara/helpers.rb +3 -3
  8. data/lib/capybara/minitest/spec.rb +3 -3
  9. data/lib/capybara/node/actions.rb +18 -18
  10. data/lib/capybara/node/base.rb +1 -1
  11. data/lib/capybara/node/element.rb +2 -2
  12. data/lib/capybara/node/finders.rb +6 -6
  13. data/lib/capybara/node/matchers.rb +5 -5
  14. data/lib/capybara/node/simple.rb +2 -2
  15. data/lib/capybara/queries/ancestor_query.rb +1 -1
  16. data/lib/capybara/queries/base_query.rb +12 -11
  17. data/lib/capybara/queries/current_path_query.rb +1 -1
  18. data/lib/capybara/queries/selector_query.rb +39 -15
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/text_query.rb +1 -1
  21. data/lib/capybara/rack_test/browser.rb +7 -7
  22. data/lib/capybara/rack_test/driver.rb +1 -1
  23. data/lib/capybara/rack_test/form.rb +7 -7
  24. data/lib/capybara/rack_test/node.rb +16 -16
  25. data/lib/capybara/rails.rb +1 -1
  26. data/lib/capybara/result.rb +8 -4
  27. data/lib/capybara/rspec/features.rb +4 -4
  28. data/lib/capybara/rspec/matchers.rb +6 -6
  29. data/lib/capybara/selector.rb +106 -90
  30. data/lib/capybara/selector/css.rb +4 -4
  31. data/lib/capybara/selector/filter_set.rb +52 -8
  32. data/lib/capybara/selector/selector.rb +39 -15
  33. data/lib/capybara/selenium/driver.rb +10 -10
  34. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -0
  35. data/lib/capybara/selenium/node.rb +9 -10
  36. data/lib/capybara/selenium/nodes/chrome_node.rb +18 -0
  37. data/lib/capybara/selenium/nodes/marionette_node.rb +32 -7
  38. data/lib/capybara/server.rb +3 -3
  39. data/lib/capybara/server/animation_disabler.rb +1 -1
  40. data/lib/capybara/server/middleware.rb +1 -1
  41. data/lib/capybara/session.rb +23 -19
  42. data/lib/capybara/session/config.rb +18 -3
  43. data/lib/capybara/spec/public/test.js +1 -1
  44. data/lib/capybara/spec/session/accept_alert_spec.rb +10 -10
  45. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
  46. data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
  47. data/lib/capybara/spec/session/all_spec.rb +33 -32
  48. data/lib/capybara/spec/session/ancestor_spec.rb +19 -19
  49. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +38 -38
  50. data/lib/capybara/spec/session/assert_current_path_spec.rb +16 -16
  51. data/lib/capybara/spec/session/assert_selector_spec.rb +53 -53
  52. data/lib/capybara/spec/session/assert_style_spec.rb +3 -3
  53. data/lib/capybara/spec/session/assert_text_spec.rb +31 -30
  54. data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
  55. data/lib/capybara/spec/session/attach_file_spec.rb +51 -52
  56. data/lib/capybara/spec/session/body_spec.rb +6 -6
  57. data/lib/capybara/spec/session/check_spec.rb +52 -47
  58. data/lib/capybara/spec/session/choose_spec.rb +32 -32
  59. data/lib/capybara/spec/session/click_button_spec.rb +103 -103
  60. data/lib/capybara/spec/session/click_link_or_button_spec.rb +24 -23
  61. data/lib/capybara/spec/session/click_link_spec.rb +49 -48
  62. data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
  63. data/lib/capybara/spec/session/current_url_spec.rb +26 -27
  64. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
  65. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
  66. data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
  67. data/lib/capybara/spec/session/element/match_css_spec.rb +10 -10
  68. data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
  69. data/lib/capybara/spec/session/element/matches_selector_spec.rb +51 -51
  70. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
  71. data/lib/capybara/spec/session/evaluate_script_spec.rb +15 -8
  72. data/lib/capybara/spec/session/execute_script_spec.rb +7 -7
  73. data/lib/capybara/spec/session/fill_in_spec.rb +43 -42
  74. data/lib/capybara/spec/session/find_button_spec.rb +23 -23
  75. data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
  76. data/lib/capybara/spec/session/find_field_spec.rb +32 -30
  77. data/lib/capybara/spec/session/find_link_spec.rb +21 -21
  78. data/lib/capybara/spec/session/find_spec.rb +153 -135
  79. data/lib/capybara/spec/session/first_spec.rb +41 -41
  80. data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
  81. data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
  82. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +17 -17
  83. data/lib/capybara/spec/session/frame/within_frame_spec.rb +31 -17
  84. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  85. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  86. data/lib/capybara/spec/session/has_all_selectors_spec.rb +17 -17
  87. data/lib/capybara/spec/session/has_button_spec.rb +13 -13
  88. data/lib/capybara/spec/session/has_css_spec.rb +133 -131
  89. data/lib/capybara/spec/session/has_current_path_spec.rb +29 -29
  90. data/lib/capybara/spec/session/has_field_spec.rb +58 -58
  91. data/lib/capybara/spec/session/has_link_spec.rb +4 -4
  92. data/lib/capybara/spec/session/has_none_selectors_spec.rb +24 -24
  93. data/lib/capybara/spec/session/has_select_spec.rb +43 -43
  94. data/lib/capybara/spec/session/has_selector_spec.rb +71 -71
  95. data/lib/capybara/spec/session/has_style_spec.rb +3 -3
  96. data/lib/capybara/spec/session/has_table_spec.rb +4 -4
  97. data/lib/capybara/spec/session/has_text_spec.rb +53 -52
  98. data/lib/capybara/spec/session/has_title_spec.rb +14 -14
  99. data/lib/capybara/spec/session/has_xpath_spec.rb +39 -38
  100. data/lib/capybara/spec/session/headers_spec.rb +1 -1
  101. data/lib/capybara/spec/session/html_spec.rb +6 -6
  102. data/lib/capybara/spec/session/node_spec.rb +129 -123
  103. data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
  104. data/lib/capybara/spec/session/refresh_spec.rb +4 -7
  105. data/lib/capybara/spec/session/reset_session_spec.rb +28 -28
  106. data/lib/capybara/spec/session/response_code_spec.rb +1 -1
  107. data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
  108. data/lib/capybara/spec/session/save_page_spec.rb +37 -37
  109. data/lib/capybara/spec/session/save_screenshot_spec.rb +6 -6
  110. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  111. data/lib/capybara/spec/session/select_spec.rb +81 -81
  112. data/lib/capybara/spec/session/selectors_spec.rb +17 -17
  113. data/lib/capybara/spec/session/sibling_spec.rb +9 -9
  114. data/lib/capybara/spec/session/text_spec.rb +23 -23
  115. data/lib/capybara/spec/session/title_spec.rb +5 -5
  116. data/lib/capybara/spec/session/uncheck_spec.rb +24 -20
  117. data/lib/capybara/spec/session/unselect_spec.rb +37 -37
  118. data/lib/capybara/spec/session/visit_spec.rb +48 -49
  119. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
  120. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -16
  121. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -2
  122. data/lib/capybara/spec/session/window/window_spec.rb +4 -4
  123. data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
  124. data/lib/capybara/spec/session/within_spec.rb +41 -41
  125. data/lib/capybara/spec/spec_helper.rb +11 -9
  126. data/lib/capybara/spec/test_app.rb +18 -17
  127. data/lib/capybara/spec/views/form.erb +29 -31
  128. data/lib/capybara/spec/views/with_html.erb +2 -2
  129. data/lib/capybara/version.rb +1 -1
  130. data/spec/basic_node_spec.rb +23 -23
  131. data/spec/capybara_spec.rb +20 -20
  132. data/spec/css_splitter_spec.rb +7 -7
  133. data/spec/dsl_spec.rb +37 -32
  134. data/spec/filter_set_spec.rb +4 -4
  135. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  136. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  137. data/spec/minitest_spec.rb +4 -4
  138. data/spec/minitest_spec_spec.rb +23 -23
  139. data/spec/per_session_config_spec.rb +5 -5
  140. data/spec/rack_test_spec.rb +44 -44
  141. data/spec/result_spec.rb +14 -14
  142. data/spec/rspec/features_spec.rb +13 -13
  143. data/spec/rspec/scenarios_spec.rb +4 -4
  144. data/spec/rspec/shared_spec_matchers.rb +282 -281
  145. data/spec/rspec/views_spec.rb +3 -3
  146. data/spec/rspec_matchers_spec.rb +10 -10
  147. data/spec/rspec_spec.rb +29 -29
  148. data/spec/selector_spec.rb +64 -64
  149. data/spec/selenium_spec_chrome.rb +14 -22
  150. data/spec/selenium_spec_chrome_remote.rb +28 -8
  151. data/spec/selenium_spec_edge.rb +9 -4
  152. data/spec/selenium_spec_firefox_remote.rb +87 -0
  153. data/spec/selenium_spec_ie.rb +9 -4
  154. data/spec/selenium_spec_marionette.rb +42 -18
  155. data/spec/server_spec.rb +29 -27
  156. data/spec/session_spec.rb +17 -17
  157. data/spec/shared_selenium_session.rb +70 -52
  158. data/spec/spec_helper.rb +1 -1
  159. metadata +4 -2
@@ -5,14 +5,14 @@ Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
5
5
  @session.visit('/with_js')
6
6
  end
7
7
 
8
- it "should dismiss the confirm" do
8
+ it 'should dismiss the confirm' do
9
9
  @session.dismiss_confirm do
10
10
  @session.click_link('Open confirm')
11
11
  end
12
12
  expect(@session).to have_xpath("//a[@id='open-confirm' and @confirmed='false']")
13
13
  end
14
14
 
15
- it "should dismiss the confirm if the message matches" do
15
+ it 'should dismiss the confirm if the message matches' do
16
16
  @session.dismiss_confirm 'Confirm opened' do
17
17
  @session.click_link('Open confirm')
18
18
  end
@@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
27
27
  end.to raise_error(Capybara::ModalNotFound)
28
28
  end
29
29
 
30
- it "should return the message presented" do
30
+ it 'should return the message presented' do
31
31
  message = @session.dismiss_confirm do
32
32
  @session.click_link('Open confirm')
33
33
  end
@@ -5,14 +5,14 @@ Capybara::SpecHelper.spec '#dismiss_prompt', requires: [:modals] do
5
5
  @session.visit('/with_js')
6
6
  end
7
7
 
8
- it "should dismiss the prompt" do
8
+ it 'should dismiss the prompt' do
9
9
  @session.dismiss_prompt do
10
10
  @session.click_link('Open prompt')
11
11
  end
12
12
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='dismissed']")
13
13
  end
14
14
 
15
- it "should return the message presented" do
15
+ it 'should return the message presented' do
16
16
  message = @session.dismiss_prompt do
17
17
  @session.click_link('Open prompt')
18
18
  end
@@ -6,19 +6,19 @@ Capybara::SpecHelper.spec '#assert_matches_selector' do
6
6
  @element = @session.find(:css, 'span', text: '42')
7
7
  end
8
8
 
9
- it "should be true if the given selector matches the element" do
9
+ it 'should be true if the given selector matches the element' do
10
10
  expect(@element.assert_matches_selector(:css, '.number')).to be true
11
11
  end
12
12
 
13
- it "should be false if the given selector does not match the element" do
13
+ it 'should be false if the given selector does not match the element' do
14
14
  expect { @element.assert_matches_selector(:css, '.not_number') }.to raise_error(Capybara::ElementNotFound)
15
15
  end
16
16
 
17
- it "should not be callable on the session" do
17
+ it 'should not be callable on the session' do
18
18
  expect { @session.assert_matches_selector(:css, '.number') }.to raise_error(NoMethodError)
19
19
  end
20
20
 
21
- it "should wait for match to occur", requires: [:js] do
21
+ it 'should wait for match to occur', requires: [:js] do
22
22
  @session.visit('/with_js')
23
23
  input = @session.find(:css, '#disable-on-click')
24
24
 
@@ -27,12 +27,12 @@ Capybara::SpecHelper.spec '#assert_matches_selector' do
27
27
  expect(input.assert_matches_selector(:css, 'input:disabled')).to be true
28
28
  end
29
29
 
30
- it "should not accept count options" do
30
+ it 'should not accept count options' do
31
31
  expect { @element.assert_matches_selector(:css, '.number', count: 1) }.to raise_error(ArgumentError, /count/)
32
32
  end
33
33
 
34
- it "should accept a filter block" do
35
- @element.assert_matches_selector(:css, 'span') { |el| el[:class] == "number" }
36
- @element.assert_not_matches_selector(:css, 'span') { |el| el[:class] == "not_number" }
34
+ it 'should accept a filter block' do
35
+ @element.assert_matches_selector(:css, 'span') { |el| el[:class] == 'number' }
36
+ @element.assert_not_matches_selector(:css, 'span') { |el| el[:class] == 'not_number' }
37
37
  end
38
38
  end
@@ -6,20 +6,20 @@ Capybara::SpecHelper.spec '#match_css?' do
6
6
  @element = @session.find(:css, 'span', text: '42')
7
7
  end
8
8
 
9
- it "should be true if the given selector matches the element" do
10
- expect(@element).to match_css("span")
11
- expect(@element).to match_css("span.number")
9
+ it 'should be true if the given selector matches the element' do
10
+ expect(@element).to match_css('span')
11
+ expect(@element).to match_css('span.number')
12
12
  end
13
13
 
14
- it "should be false if the given selector does not match" do
15
- expect(@element).not_to match_css("div")
16
- expect(@element).not_to match_css("p a#doesnotexist")
17
- expect(@element).not_to match_css("p.nosuchclass")
14
+ it 'should be false if the given selector does not match' do
15
+ expect(@element).not_to match_css('div')
16
+ expect(@element).not_to match_css('p a#doesnotexist')
17
+ expect(@element).not_to match_css('p.nosuchclass')
18
18
  end
19
19
 
20
- it "should accept an optional filter block" do
20
+ it 'should accept an optional filter block' do
21
21
  # This would be better done with
22
- expect(@element).to match_css('span') { |el| el[:class] == "number" }
23
- expect(@element).not_to match_css('span') { |el| el[:class] == "not_number" }
22
+ expect(@element).to match_css('span') { |el| el[:class] == 'number' }
23
+ expect(@element).not_to match_css('span') { |el| el[:class] == 'not_number' }
24
24
  end
25
25
  end
@@ -6,18 +6,18 @@ Capybara::SpecHelper.spec '#match_xpath?' do
6
6
  @element = @session.find(:css, 'span.number')
7
7
  end
8
8
 
9
- it "should be true if the given selector is on the page" do
10
- expect(@element).to match_xpath("//span")
9
+ it 'should be true if the given selector is on the page' do
10
+ expect(@element).to match_xpath('//span')
11
11
  expect(@element).to match_xpath("//span[@class='number']")
12
12
  end
13
13
 
14
- it "should be false if the given selector is not on the page" do
15
- expect(@element).not_to match_xpath("//abbr")
16
- expect(@element).not_to match_xpath("//div")
14
+ it 'should be false if the given selector is not on the page' do
15
+ expect(@element).not_to match_xpath('//abbr')
16
+ expect(@element).not_to match_xpath('//div')
17
17
  expect(@element).not_to match_xpath("//span[@class='not_a_number']")
18
18
  end
19
19
 
20
- it "should use xpath even if default selector is CSS" do
20
+ it 'should use xpath even if default selector is CSS' do
21
21
  Capybara.default_selector = :css
22
22
  expect(@element).not_to have_xpath("//span[@class='not_a_number']")
23
23
  expect(@element).not_to have_xpath("//div[@class='number']")
@@ -6,43 +6,43 @@ Capybara::SpecHelper.spec '#match_selector?' do
6
6
  @element = @session.find('//span', text: '42')
7
7
  end
8
8
 
9
- it "should be true if the element matches the given selector" do
10
- expect(@element).to match_selector(:xpath, "//span")
9
+ it 'should be true if the element matches the given selector' do
10
+ expect(@element).to match_selector(:xpath, '//span')
11
11
  expect(@element).to match_selector(:css, 'span.number')
12
12
  expect(@element.matches_selector?(:css, 'span.number')).to be true
13
13
  end
14
14
 
15
- it "should be false if the element does not match the given selector" do
16
- expect(@element).not_to match_selector(:xpath, "//div")
17
- expect(@element).not_to match_selector(:css, "span.not_a_number")
18
- expect(@element.matches_selector?(:css, "span.not_a_number")).to be false
15
+ it 'should be false if the element does not match the given selector' do
16
+ expect(@element).not_to match_selector(:xpath, '//div')
17
+ expect(@element).not_to match_selector(:css, 'span.not_a_number')
18
+ expect(@element.matches_selector?(:css, 'span.not_a_number')).to be false
19
19
  end
20
20
 
21
- it "should use default selector" do
21
+ it 'should use default selector' do
22
22
  Capybara.default_selector = :css
23
- expect(@element).not_to match_selector("span.not_a_number")
24
- expect(@element).to match_selector("span.number")
23
+ expect(@element).not_to match_selector('span.not_a_number')
24
+ expect(@element).to match_selector('span.number')
25
25
  end
26
26
 
27
- context "with text" do
28
- it "should discard all matches where the given string is not contained" do
29
- expect(@element).to match_selector("//span", text: "42")
30
- expect(@element).not_to match_selector("//span", text: "Doesnotexist")
27
+ context 'with text' do
28
+ it 'should discard all matches where the given string is not contained' do
29
+ expect(@element).to match_selector('//span', text: '42')
30
+ expect(@element).not_to match_selector('//span', text: 'Doesnotexist')
31
31
  end
32
32
  end
33
33
 
34
- it "should have css sugar" do
34
+ it 'should have css sugar' do
35
35
  expect(@element.matches_css?('span.number')).to be true
36
36
  expect(@element.matches_css?('span.not_a_number')).to be false
37
- expect(@element.matches_css?('span.number', text: "42")).to be true
38
- expect(@element.matches_css?('span.number', text: "Nope")).to be false
37
+ expect(@element.matches_css?('span.number', text: '42')).to be true
38
+ expect(@element.matches_css?('span.number', text: 'Nope')).to be false
39
39
  end
40
40
 
41
- it "should have xpath sugar" do
42
- expect(@element.matches_xpath?("//span")).to be true
43
- expect(@element.matches_xpath?("//div")).to be false
44
- expect(@element.matches_xpath?("//span", text: '42')).to be true
45
- expect(@element.matches_xpath?("//span", text: 'Nope')).to be false
41
+ it 'should have xpath sugar' do
42
+ expect(@element.matches_xpath?('//span')).to be true
43
+ expect(@element.matches_xpath?('//div')).to be false
44
+ expect(@element.matches_xpath?('//span', text: '42')).to be true
45
+ expect(@element.matches_xpath?('//span', text: 'Nope')).to be false
46
46
  end
47
47
 
48
48
  it 'should accept selector filters' do
@@ -54,55 +54,55 @@ Capybara::SpecHelper.spec '#match_selector?' do
54
54
  it 'should accept a custom filter block' do
55
55
  @session.visit('/form')
56
56
  cbox = @session.find(:css, '#form_pets_dog')
57
- expect(cbox).to match_selector(:checkbox) { |node| node[:id] == "form_pets_dog" }
58
- expect(cbox).not_to match_selector(:checkbox) { |node| node[:id] != "form_pets_dog" }
59
- expect(cbox.matches_selector?(:checkbox) { |node| node[:id] == "form_pets_dog" }).to be true
60
- expect(cbox.matches_selector?(:checkbox) { |node| node[:id] != "form_pets_dog" }).to be false
57
+ expect(cbox).to match_selector(:checkbox) { |node| node[:id] == 'form_pets_dog' }
58
+ expect(cbox).not_to match_selector(:checkbox) { |node| node[:id] != 'form_pets_dog' }
59
+ expect(cbox.matches_selector?(:checkbox) { |node| node[:id] == 'form_pets_dog' }).to be true
60
+ expect(cbox.matches_selector?(:checkbox) { |node| node[:id] != 'form_pets_dog' }).to be false
61
61
  end
62
62
  end
63
63
 
64
64
  Capybara::SpecHelper.spec '#not_matches_selector?' do
65
65
  before do
66
66
  @session.visit('/with_html')
67
- @element = @session.find(:css, "span", text: 42)
67
+ @element = @session.find(:css, 'span', text: 42)
68
68
  end
69
69
 
70
- it "should be false if the given selector matches the element" do
71
- expect(@element).not_to not_match_selector(:xpath, "//span")
72
- expect(@element).not_to not_match_selector(:css, "span.number")
73
- expect(@element.not_matches_selector?(:css, "span.number")).to be false
70
+ it 'should be false if the given selector matches the element' do
71
+ expect(@element).not_to not_match_selector(:xpath, '//span')
72
+ expect(@element).not_to not_match_selector(:css, 'span.number')
73
+ expect(@element.not_matches_selector?(:css, 'span.number')).to be false
74
74
  end
75
75
 
76
- it "should be true if the given selector does not match the element" do
77
- expect(@element).to not_match_selector(:xpath, "//abbr")
78
- expect(@element).to not_match_selector(:css, "p a#doesnotexist")
79
- expect(@element.not_matches_selector?(:css, "p a#doesnotexist")).to be true
76
+ it 'should be true if the given selector does not match the element' do
77
+ expect(@element).to not_match_selector(:xpath, '//abbr')
78
+ expect(@element).to not_match_selector(:css, 'p a#doesnotexist')
79
+ expect(@element.not_matches_selector?(:css, 'p a#doesnotexist')).to be true
80
80
  end
81
81
 
82
- it "should use default selector" do
82
+ it 'should use default selector' do
83
83
  Capybara.default_selector = :css
84
- expect(@element).to not_match_selector("p a#doesnotexist")
85
- expect(@element).not_to not_match_selector("span.number")
84
+ expect(@element).to not_match_selector('p a#doesnotexist')
85
+ expect(@element).not_to not_match_selector('span.number')
86
86
  end
87
87
 
88
- context "with text" do
89
- it "should discard all matches where the given string is contained" do
90
- expect(@element).not_to not_match_selector(:css, "span.number", text: "42")
91
- expect(@element).to not_match_selector(:css, "span.number", text: "Doesnotexist")
88
+ context 'with text' do
89
+ it 'should discard all matches where the given string is contained' do
90
+ expect(@element).not_to not_match_selector(:css, 'span.number', text: '42')
91
+ expect(@element).to not_match_selector(:css, 'span.number', text: 'Doesnotexist')
92
92
  end
93
93
  end
94
94
 
95
- it "should have CSS sugar" do
96
- expect(@element.not_matches_css?("span.number")).to be false
97
- expect(@element.not_matches_css?("p a#doesnotexist")).to be true
98
- expect(@element.not_matches_css?("span.number", text: "42")).to be false
99
- expect(@element.not_matches_css?("span.number", text: "Doesnotexist")).to be true
95
+ it 'should have CSS sugar' do
96
+ expect(@element.not_matches_css?('span.number')).to be false
97
+ expect(@element.not_matches_css?('p a#doesnotexist')).to be true
98
+ expect(@element.not_matches_css?('span.number', text: '42')).to be false
99
+ expect(@element.not_matches_css?('span.number', text: 'Doesnotexist')).to be true
100
100
  end
101
101
 
102
- it "should have xpath sugar" do
103
- expect(@element.not_matches_xpath?("//span")).to be false
104
- expect(@element.not_matches_xpath?("//div")).to be true
105
- expect(@element.not_matches_xpath?("//span", text: "42")).to be false
106
- expect(@element.not_matches_xpath?("//span", text: "Doesnotexist")).to be true
102
+ it 'should have xpath sugar' do
103
+ expect(@element.not_matches_xpath?('//span')).to be false
104
+ expect(@element.not_matches_xpath?('//div')).to be true
105
+ expect(@element.not_matches_xpath?('//span', text: '42')).to be false
106
+ expect(@element.not_matches_xpath?('//span', text: 'Doesnotexist')).to be true
107
107
  end
108
108
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#evaluate_async_script", requires: [:js] do
4
- it "should evaluate the given script and return whatever it produces" do
3
+ Capybara::SpecHelper.spec '#evaluate_async_script', requires: [:js] do
4
+ it 'should evaluate the given script and return whatever it produces' do
5
5
  @session.visit('/with_js')
6
- expect(@session.evaluate_async_script("arguments[0](4)")).to eq(4)
6
+ expect(@session.evaluate_async_script('arguments[0](4)')).to eq(4)
7
7
  end
8
8
 
9
- it "should support passing elements as arguments to the script", requires: %i[js es_args] do
9
+ it 'should support passing elements as arguments to the script', requires: %i[js es_args] do
10
10
  @session.visit('/with_js')
11
11
  el = @session.find(:css, '#drag p')
12
- result = @session.evaluate_async_script("arguments[2]([arguments[0].innerText, arguments[1]])", el, "Doodle Funk")
13
- expect(result).to eq ["This is a draggable element.", "Doodle Funk"]
12
+ result = @session.evaluate_async_script('arguments[2]([arguments[0].innerText, arguments[1]])', el, 'Doodle Funk')
13
+ expect(result).to eq ['This is a draggable element.', 'Doodle Funk']
14
14
  end
15
15
 
16
- it "should support returning elements after asynchronous operation", requires: %i[js es_args] do
16
+ it 'should support returning elements after asynchronous operation', requires: %i[js es_args] do
17
17
  @session.visit('/with_js')
18
18
  @session.find(:css, '#change') # ensure page has loaded and element is available
19
19
  el = @session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(document.getElementById('change')) }, 100)")
@@ -1,25 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#evaluate_script", requires: [:js] do
4
- it "should evaluate the given script and return whatever it produces" do
3
+ Capybara::SpecHelper.spec '#evaluate_script', requires: [:js] do
4
+ it 'should evaluate the given script and return whatever it produces' do
5
5
  @session.visit('/with_js')
6
- expect(@session.evaluate_script("1+3")).to eq(4)
6
+ expect(@session.evaluate_script('1+3')).to eq(4)
7
7
  end
8
8
 
9
- it "should pass arguments to the script", requires: %i[js es_args] do
9
+ it 'should ignore leading whitespace' do
10
10
  @session.visit('/with_js')
11
- @session.evaluate_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
11
+ expect(@session.evaluate_script('
12
+ 1 + 3
13
+ ')).to eq(4)
14
+ end
15
+
16
+ it 'should pass arguments to the script', requires: %i[js es_args] do
17
+ @session.visit('/with_js')
18
+ @session.evaluate_script("document.getElementById('change').textContent = arguments[0]", 'Doodle Funk')
12
19
  expect(@session).to have_css('#change', text: 'Doodle Funk')
13
20
  end
14
21
 
15
- it "should support passing elements as arguments to the script", requires: %i[js es_args] do
22
+ it 'should support passing elements as arguments to the script', requires: %i[js es_args] do
16
23
  @session.visit('/with_js')
17
24
  el = @session.find(:css, '#change')
18
- @session.evaluate_script("arguments[0].textContent = arguments[1]", el, "Doodle Funk")
25
+ @session.evaluate_script('arguments[0].textContent = arguments[1]', el, 'Doodle Funk')
19
26
  expect(@session).to have_css('#change', text: 'Doodle Funk')
20
27
  end
21
28
 
22
- it "should support returning elements", requires: %i[js es_args] do
29
+ it 'should support returning elements', requires: %i[js es_args] do
23
30
  @session.visit('/with_js')
24
31
  @session.find(:css, '#change') # ensure page has loaded and element is available
25
32
  el = @session.evaluate_script("document.getElementById('change')")
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
4
- it "should execute the given script and return nothing" do
3
+ Capybara::SpecHelper.spec '#execute_script', requires: [:js] do
4
+ it 'should execute the given script and return nothing' do
5
5
  @session.visit('/with_js')
6
6
  expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
7
7
  expect(@session).to have_css('#change', text: 'Funky Doodle')
8
8
  end
9
9
 
10
- it "should be able to call functions defined in the page" do
10
+ it 'should be able to call functions defined in the page' do
11
11
  @session.visit('/with_js')
12
12
  expect { @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
13
13
  end
14
14
 
15
- it "should pass arguments to the script", requires: %i[js es_args] do
15
+ it 'should pass arguments to the script', requires: %i[js es_args] do
16
16
  @session.visit('/with_js')
17
- @session.execute_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
17
+ @session.execute_script("document.getElementById('change').textContent = arguments[0]", 'Doodle Funk')
18
18
  expect(@session).to have_css('#change', text: 'Doodle Funk')
19
19
  end
20
20
 
21
- it "should support passing elements as arguments to the script", requires: %i[js es_args] do
21
+ it 'should support passing elements as arguments to the script', requires: %i[js es_args] do
22
22
  @session.visit('/with_js')
23
23
  el = @session.find(:css, '#change')
24
- @session.execute_script("arguments[1].textContent = arguments[0]", "Doodle Funk", el)
24
+ @session.execute_script('arguments[1].textContent = arguments[0]', 'Doodle Funk', el)
25
25
  expect(@session).to have_css('#change', text: 'Doodle Funk')
26
26
  end
27
27
  end
@@ -1,67 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#fill_in" do
3
+ Capybara::SpecHelper.spec '#fill_in' do
4
4
  before do
5
5
  @session.visit('/form')
6
6
  end
7
7
 
8
- it "should fill in a text field by id" do
8
+ it 'should fill in a text field by id' do
9
9
  @session.fill_in('form_first_name', with: 'Harry')
10
10
  @session.click_button('awesome')
11
11
  expect(extract_results(@session)['first_name']).to eq('Harry')
12
12
  end
13
13
 
14
- it "should fill in a text field by name" do
14
+ it 'should fill in a text field by name' do
15
15
  @session.fill_in('form[last_name]', with: 'Green')
16
16
  @session.click_button('awesome')
17
17
  expect(extract_results(@session)['last_name']).to eq('Green')
18
18
  end
19
19
 
20
- it "should fill in a text field by label without for" do
20
+ it 'should fill in a text field by label without for' do
21
21
  @session.fill_in('First Name', with: 'Harry')
22
22
  @session.click_button('awesome')
23
23
  expect(extract_results(@session)['first_name']).to eq('Harry')
24
24
  end
25
25
 
26
- it "should fill in a url field by label without for" do
26
+ it 'should fill in a url field by label without for' do
27
27
  @session.fill_in('Html5 Url', with: 'http://www.avenueq.com')
28
28
  @session.click_button('html5_submit')
29
29
  expect(extract_results(@session)['html5_url']).to eq('http://www.avenueq.com')
30
30
  end
31
31
 
32
- it "should fill in a textarea by id" do
32
+ it 'should fill in a textarea by id' do
33
33
  @session.fill_in('form_description', with: 'Texty text')
34
34
  @session.click_button('awesome')
35
35
  expect(extract_results(@session)['description']).to eq('Texty text')
36
36
  end
37
37
 
38
- it "should fill in a textarea by label" do
38
+ it 'should fill in a textarea by label' do
39
39
  @session.fill_in('Description', with: 'Texty text')
40
40
  @session.click_button('awesome')
41
41
  expect(extract_results(@session)['description']).to eq('Texty text')
42
42
  end
43
43
 
44
- it "should fill in a textarea by name" do
44
+ it 'should fill in a textarea by name' do
45
45
  @session.fill_in('form[description]', with: 'Texty text')
46
46
  @session.click_button('awesome')
47
47
  expect(extract_results(@session)['description']).to eq('Texty text')
48
48
  end
49
49
 
50
- it "should fill in a password field by id" do
50
+ it 'should fill in a password field by id' do
51
51
  @session.fill_in('form_password', with: 'supasikrit')
52
52
  @session.click_button('awesome')
53
53
  expect(extract_results(@session)['password']).to eq('supasikrit')
54
54
  end
55
55
 
56
- context "Date/Time" do
57
- it "should fill in a date input" do
56
+ context 'Date/Time' do
57
+ it 'should fill in a date input' do
58
58
  date = Date.today
59
59
  @session.fill_in('form_date', with: date)
60
60
  @session.click_button('awesome')
61
61
  expect(Date.parse(extract_results(@session)['date'])).to eq date
62
62
  end
63
63
 
64
- it "should fill in a time input" do
64
+ it 'should fill in a time input' do
65
65
  time = Time.new(2018, 3, 9, 15, 26)
66
66
  @session.fill_in('form_time', with: time)
67
67
  @session.click_button('awesome')
@@ -69,7 +69,7 @@ Capybara::SpecHelper.spec "#fill_in" do
69
69
  expect(Time.parse(results).strftime('%r')).to eq time.strftime('%r')
70
70
  end
71
71
 
72
- it "should fill in a datetime input" do
72
+ it 'should fill in a datetime input' do
73
73
  dt = Time.new(2018, 3, 13, 9, 53)
74
74
  @session.fill_in('form_datetime', with: dt)
75
75
  @session.click_button('awesome')
@@ -77,61 +77,61 @@ Capybara::SpecHelper.spec "#fill_in" do
77
77
  end
78
78
  end
79
79
 
80
- it "should handle HTML in a textarea" do
80
+ it 'should handle HTML in a textarea' do
81
81
  @session.fill_in('form_description', with: 'is <strong>very</strong> secret!')
82
82
  @session.click_button('awesome')
83
83
  expect(extract_results(@session)['description']).to eq('is <strong>very</strong> secret!')
84
84
  end
85
85
 
86
- it "should handle newlines in a textarea" do
86
+ it 'should handle newlines in a textarea' do
87
87
  @session.fill_in('form_description', with: "\nSome text\n")
88
88
  @session.click_button('awesome')
89
89
  expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n")
90
90
  end
91
91
 
92
- it "should fill in a field with a custom type" do
92
+ it 'should fill in a field with a custom type' do
93
93
  @session.fill_in('Schmooo', with: 'Schmooo is the game')
94
94
  @session.click_button('awesome')
95
95
  expect(extract_results(@session)['schmooo']).to eq('Schmooo is the game')
96
96
  end
97
97
 
98
- it "should fill in a field without a type" do
98
+ it 'should fill in a field without a type' do
99
99
  @session.fill_in('Phone', with: '+1 555 7022')
100
100
  @session.click_button('awesome')
101
101
  expect(extract_results(@session)['phone']).to eq('+1 555 7022')
102
102
  end
103
103
 
104
- it "should fill in a text field respecting its maxlength attribute" do
104
+ it 'should fill in a text field respecting its maxlength attribute' do
105
105
  @session.fill_in('Zipcode', with: '52071350')
106
106
  @session.click_button('awesome')
107
107
  expect(extract_results(@session)['zipcode']).to eq('52071')
108
108
  end
109
109
 
110
- it "should fill in a password field by name" do
110
+ it 'should fill in a password field by name' do
111
111
  @session.fill_in('form[password]', with: 'supasikrit')
112
112
  @session.click_button('awesome')
113
113
  expect(extract_results(@session)['password']).to eq('supasikrit')
114
114
  end
115
115
 
116
- it "should fill in a password field by label" do
116
+ it 'should fill in a password field by label' do
117
117
  @session.fill_in('Password', with: 'supasikrit')
118
118
  @session.click_button('awesome')
119
119
  expect(extract_results(@session)['password']).to eq('supasikrit')
120
120
  end
121
121
 
122
- it "should fill in a password field by name" do
122
+ it 'should fill in a password field by name' do
123
123
  @session.fill_in('form[password]', with: 'supasikrit')
124
124
  @session.click_button('awesome')
125
125
  expect(extract_results(@session)['password']).to eq('supasikrit')
126
126
  end
127
127
 
128
- it "should fill in a field based on current value" do
128
+ it 'should fill in a field based on current value' do
129
129
  @session.fill_in(currently_with: 'John', with: 'Thomas')
130
130
  @session.click_button('awesome')
131
131
  expect(extract_results(@session)['first_name']).to eq('Thomas')
132
132
  end
133
133
 
134
- it "should fill in a field based on type" do
134
+ it 'should fill in a field based on type' do
135
135
  @session.fill_in(type: 'schmooo', with: 'Schmooo for all')
136
136
  @session.click_button('awesome')
137
137
  expect(extract_results(@session)['schmooo']).to eq('Schmooo for all')
@@ -141,25 +141,26 @@ Capybara::SpecHelper.spec "#fill_in" do
141
141
  expect { @session.fill_in 'Name' }.to raise_error(ArgumentError, /with/)
142
142
  end
143
143
 
144
- it "should wait for asynchronous load", requires: [:js] do
144
+ it 'should wait for asynchronous load', requires: [:js] do
145
+ Capybara.default_max_wait_time = 2
145
146
  @session.visit('/with_js')
146
147
  @session.click_link('Click me')
147
148
  @session.fill_in('new_field', with: 'Testing...')
148
149
  end
149
150
 
150
- it "casts to string" do
151
+ it 'casts to string' do
151
152
  @session.fill_in(:form_first_name, with: :Harry)
152
153
  @session.click_button('awesome')
153
154
  expect(extract_results(@session)['first_name']).to eq('Harry')
154
155
  end
155
156
 
156
- it "casts to string if field has maxlength" do
157
+ it 'casts to string if field has maxlength' do
157
158
  @session.fill_in(:form_zipcode, with: 1234567)
158
159
  @session.click_button('awesome')
159
160
  expect(extract_results(@session)['zipcode']).to eq('12345')
160
161
  end
161
162
 
162
- it "fills in a field if default_set_options is nil" do
163
+ it 'fills in a field if default_set_options is nil' do
163
164
  Capybara.default_set_options = nil
164
165
  @session.fill_in(:form_first_name, with: 'Thomas')
165
166
  @session.click_button('awesome')
@@ -186,13 +187,13 @@ Capybara::SpecHelper.spec "#fill_in" do
186
187
  end
187
188
  end
188
189
 
189
- context "with ignore_hidden_fields" do
190
+ context 'with ignore_hidden_fields' do
190
191
  before { Capybara.ignore_hidden_elements = true }
191
192
 
192
193
  after { Capybara.ignore_hidden_elements = false }
193
194
 
194
- it "should not find a hidden field" do
195
- msg = "Unable to find visible field \"Super Secret\" that is not disabled"
195
+ it 'should not find a hidden field' do
196
+ msg = 'Unable to find visible field "Super Secret"'
196
197
  expect do
197
198
  @session.fill_in('Super Secret', with: '777')
198
199
  end.to raise_error(Capybara::ElementNotFound, msg)
@@ -200,37 +201,37 @@ Capybara::SpecHelper.spec "#fill_in" do
200
201
  end
201
202
 
202
203
  context "with a locator that doesn't exist" do
203
- it "should raise an error" do
204
- msg = "Unable to find visible field \"does not exist\" that is not disabled"
204
+ it 'should raise an error' do
205
+ msg = 'Unable to find field "does not exist"'
205
206
  expect do
206
207
  @session.fill_in('does not exist', with: 'Blah blah')
207
208
  end.to raise_error(Capybara::ElementNotFound, msg)
208
209
  end
209
210
  end
210
211
 
211
- context "on a disabled field" do
212
- it "should raise an error" do
212
+ context 'on a disabled field' do
213
+ it 'should raise an error' do
213
214
  expect do
214
215
  @session.fill_in('Disabled Text Field', with: 'Blah blah')
215
216
  end.to raise_error(Capybara::ElementNotFound)
216
217
  end
217
218
  end
218
219
 
219
- context "with :exact option" do
220
- it "should accept partial matches when false" do
221
- @session.fill_in("Explanation", with: "Dude", exact: false)
222
- @session.click_button("awesome")
223
- expect(extract_results(@session)["name_explanation"]).to eq("Dude")
220
+ context 'with :exact option' do
221
+ it 'should accept partial matches when false' do
222
+ @session.fill_in('Explanation', with: 'Dude', exact: false)
223
+ @session.click_button('awesome')
224
+ expect(extract_results(@session)['name_explanation']).to eq('Dude')
224
225
  end
225
226
 
226
- it "should not accept partial matches when true" do
227
+ it 'should not accept partial matches when true' do
227
228
  expect do
228
- @session.fill_in("Explanation", with: "Dude", exact: true)
229
+ @session.fill_in('Explanation', with: 'Dude', exact: true)
229
230
  end.to raise_error(Capybara::ElementNotFound)
230
231
  end
231
232
  end
232
233
 
233
- it "should return the element filled in" do
234
+ it 'should return the element filled in' do
234
235
  el = @session.find(:fillable_field, 'form_first_name')
235
236
  expect(@session.fill_in('form_first_name', with: 'Harry')).to eq el
236
237
  end