capybara 3.23.0 → 3.35.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +264 -11
  3. data/README.md +10 -6
  4. data/lib/capybara.rb +20 -8
  5. data/lib/capybara/config.rb +10 -8
  6. data/lib/capybara/cucumber.rb +1 -1
  7. data/lib/capybara/driver/base.rb +4 -0
  8. data/lib/capybara/driver/node.rb +4 -0
  9. data/lib/capybara/dsl.rb +10 -2
  10. data/lib/capybara/helpers.rb +28 -2
  11. data/lib/capybara/minitest.rb +232 -144
  12. data/lib/capybara/minitest/spec.rb +156 -97
  13. data/lib/capybara/node/actions.rb +36 -36
  14. data/lib/capybara/node/base.rb +6 -6
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +3 -3
  17. data/lib/capybara/node/element.rb +77 -33
  18. data/lib/capybara/node/finders.rb +24 -17
  19. data/lib/capybara/node/matchers.rb +79 -64
  20. data/lib/capybara/node/simple.rb +11 -4
  21. data/lib/capybara/queries/ancestor_query.rb +6 -10
  22. data/lib/capybara/queries/base_query.rb +2 -1
  23. data/lib/capybara/queries/current_path_query.rb +14 -4
  24. data/lib/capybara/queries/selector_query.rb +259 -23
  25. data/lib/capybara/queries/sibling_query.rb +5 -11
  26. data/lib/capybara/queries/style_query.rb +1 -1
  27. data/lib/capybara/queries/text_query.rb +13 -1
  28. data/lib/capybara/rack_test/browser.rb +13 -4
  29. data/lib/capybara/rack_test/driver.rb +2 -1
  30. data/lib/capybara/rack_test/form.rb +2 -2
  31. data/lib/capybara/rack_test/node.rb +42 -6
  32. data/lib/capybara/registration_container.rb +44 -0
  33. data/lib/capybara/registrations/drivers.rb +18 -12
  34. data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  35. data/lib/capybara/registrations/servers.rb +9 -2
  36. data/lib/capybara/result.rb +39 -19
  37. data/lib/capybara/rspec.rb +2 -0
  38. data/lib/capybara/rspec/matcher_proxies.rb +5 -5
  39. data/lib/capybara/rspec/matchers.rb +97 -74
  40. data/lib/capybara/rspec/matchers/base.rb +19 -6
  41. data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
  42. data/lib/capybara/rspec/matchers/have_ancestor.rb +5 -7
  43. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  44. data/lib/capybara/rspec/matchers/have_selector.rb +15 -10
  45. data/lib/capybara/rspec/matchers/have_sibling.rb +4 -7
  46. data/lib/capybara/rspec/matchers/have_text.rb +4 -7
  47. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  48. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  49. data/lib/capybara/rspec/matchers/match_style.rb +7 -2
  50. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  51. data/lib/capybara/selector.rb +46 -19
  52. data/lib/capybara/selector/builders/css_builder.rb +10 -6
  53. data/lib/capybara/selector/builders/xpath_builder.rb +4 -2
  54. data/lib/capybara/selector/css.rb +1 -1
  55. data/lib/capybara/selector/definition.rb +13 -11
  56. data/lib/capybara/selector/definition/button.rb +32 -15
  57. data/lib/capybara/selector/definition/checkbox.rb +2 -2
  58. data/lib/capybara/selector/definition/css.rb +3 -1
  59. data/lib/capybara/selector/definition/datalist_input.rb +2 -2
  60. data/lib/capybara/selector/definition/datalist_option.rb +1 -1
  61. data/lib/capybara/selector/definition/element.rb +3 -2
  62. data/lib/capybara/selector/definition/field.rb +1 -1
  63. data/lib/capybara/selector/definition/file_field.rb +1 -1
  64. data/lib/capybara/selector/definition/fillable_field.rb +2 -2
  65. data/lib/capybara/selector/definition/label.rb +5 -3
  66. data/lib/capybara/selector/definition/link.rb +8 -0
  67. data/lib/capybara/selector/definition/option.rb +1 -1
  68. data/lib/capybara/selector/definition/radio_button.rb +2 -2
  69. data/lib/capybara/selector/definition/select.rb +33 -14
  70. data/lib/capybara/selector/definition/table.rb +6 -3
  71. data/lib/capybara/selector/definition/table_row.rb +2 -2
  72. data/lib/capybara/selector/filter_set.rb +13 -11
  73. data/lib/capybara/selector/filters/base.rb +6 -1
  74. data/lib/capybara/selector/filters/locator_filter.rb +1 -1
  75. data/lib/capybara/selector/regexp_disassembler.rb +7 -0
  76. data/lib/capybara/selector/selector.rb +13 -3
  77. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  78. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -1
  79. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  80. data/lib/capybara/selenium/atoms/src/isDisplayed.js +10 -10
  81. data/lib/capybara/selenium/driver.rb +86 -24
  82. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +24 -21
  83. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +21 -19
  84. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +17 -1
  85. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +0 -4
  86. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  87. data/lib/capybara/selenium/extensions/find.rb +37 -26
  88. data/lib/capybara/selenium/extensions/html5_drag.rb +55 -11
  89. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  90. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  91. data/lib/capybara/selenium/logger_suppressor.rb +8 -2
  92. data/lib/capybara/selenium/node.rb +160 -40
  93. data/lib/capybara/selenium/nodes/chrome_node.rb +72 -12
  94. data/lib/capybara/selenium/nodes/edge_node.rb +32 -14
  95. data/lib/capybara/selenium/nodes/firefox_node.rb +28 -32
  96. data/lib/capybara/selenium/nodes/safari_node.rb +5 -29
  97. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  98. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  99. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  100. data/lib/capybara/selenium/patches/logs.rb +32 -7
  101. data/lib/capybara/server.rb +19 -3
  102. data/lib/capybara/server/animation_disabler.rb +8 -3
  103. data/lib/capybara/server/checker.rb +1 -1
  104. data/lib/capybara/server/middleware.rb +22 -10
  105. data/lib/capybara/session.rb +66 -40
  106. data/lib/capybara/session/config.rb +11 -3
  107. data/lib/capybara/session/matchers.rb +11 -11
  108. data/lib/capybara/spec/public/offset.js +6 -0
  109. data/lib/capybara/spec/public/test.js +75 -7
  110. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  111. data/lib/capybara/spec/session/all_spec.rb +60 -5
  112. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  113. data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
  114. data/lib/capybara/spec/session/check_spec.rb +6 -0
  115. data/lib/capybara/spec/session/click_button_spec.rb +16 -0
  116. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  117. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  118. data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
  119. data/lib/capybara/spec/session/find_spec.rb +55 -0
  120. data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -0
  121. data/lib/capybara/spec/session/has_button_spec.rb +51 -0
  122. data/lib/capybara/spec/session/has_css_spec.rb +26 -4
  123. data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
  124. data/lib/capybara/spec/session/has_field_spec.rb +34 -0
  125. data/lib/capybara/spec/session/has_select_spec.rb +32 -4
  126. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  127. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  128. data/lib/capybara/spec/session/has_text_spec.rb +30 -0
  129. data/lib/capybara/spec/session/html_spec.rb +1 -1
  130. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  131. data/lib/capybara/spec/session/node_spec.rb +394 -9
  132. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  133. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  134. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  135. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -15
  136. data/lib/capybara/spec/session/selectors_spec.rb +16 -3
  137. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  138. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  139. data/lib/capybara/spec/session/window/window_spec.rb +8 -8
  140. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  141. data/lib/capybara/spec/spec_helper.rb +14 -14
  142. data/lib/capybara/spec/test_app.rb +27 -21
  143. data/lib/capybara/spec/views/form.erb +47 -4
  144. data/lib/capybara/spec/views/offset.erb +32 -0
  145. data/lib/capybara/spec/views/spatial.erb +31 -0
  146. data/lib/capybara/spec/views/with_animation.erb +37 -1
  147. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  148. data/lib/capybara/spec/views/with_html.erb +24 -2
  149. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  150. data/lib/capybara/spec/views/with_js.erb +4 -1
  151. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  152. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  153. data/lib/capybara/version.rb +1 -1
  154. data/lib/capybara/window.rb +3 -7
  155. data/spec/basic_node_spec.rb +15 -14
  156. data/spec/capybara_spec.rb +28 -28
  157. data/spec/dsl_spec.rb +16 -3
  158. data/spec/filter_set_spec.rb +5 -5
  159. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  160. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  161. data/spec/minitest_spec.rb +3 -2
  162. data/spec/minitest_spec_spec.rb +46 -46
  163. data/spec/rack_test_spec.rb +38 -15
  164. data/spec/regexp_dissassembler_spec.rb +52 -38
  165. data/spec/result_spec.rb +43 -32
  166. data/spec/rspec/features_spec.rb +4 -1
  167. data/spec/rspec/scenarios_spec.rb +4 -0
  168. data/spec/rspec/shared_spec_matchers.rb +68 -56
  169. data/spec/rspec_spec.rb +9 -5
  170. data/spec/selector_spec.rb +32 -17
  171. data/spec/selenium_spec_chrome.rb +78 -11
  172. data/spec/selenium_spec_chrome_remote.rb +23 -6
  173. data/spec/selenium_spec_edge.rb +15 -12
  174. data/spec/selenium_spec_firefox.rb +24 -19
  175. data/spec/selenium_spec_firefox_remote.rb +0 -8
  176. data/spec/selenium_spec_ie.rb +1 -6
  177. data/spec/server_spec.rb +106 -44
  178. data/spec/session_spec.rb +5 -5
  179. data/spec/shared_selenium_node.rb +56 -2
  180. data/spec/shared_selenium_session.rb +122 -15
  181. data/spec/spec_helper.rb +2 -2
  182. metadata +63 -17
  183. data/lib/capybara/spec/session/source_spec.rb +0 -0
@@ -0,0 +1,32 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
+ <title>Offset</title>
5
+ <style>
6
+ body {
7
+ margin: 0px;
8
+ }
9
+ #wrapper {
10
+ width: 300px;
11
+ height: 300px;
12
+ margin: 0px;
13
+ }
14
+ #clicker {
15
+ position: relative;
16
+ width: 100px;
17
+ height: 100px;
18
+ top: 100px;
19
+ left: 100px;
20
+ background-color: red;
21
+ margin: 0px;
22
+ }
23
+ </style>
24
+ <script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
25
+ <script src="/offset.js" type="text/javascript" charset="utf-8"></script>
26
+ </head>
27
+ <body>
28
+ <div id="wrapper">
29
+ <div id="clicker"></div>
30
+ </div>
31
+ </body>
32
+ </html>
@@ -0,0 +1,31 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
+ <title>spatial</title>
5
+ <style>
6
+ #spatial {
7
+ display: grid;
8
+ grid-template-columns: repeat(3, 1fr);
9
+ grid-gap: 10px;
10
+ grid-auto-rows: minmax(100px, auto);
11
+ }
12
+ .footer {
13
+ grid-column: 1 / 4;
14
+ }
15
+ </style>
16
+ </head>
17
+
18
+ <body id="spatial">
19
+ <div class="corner">1</div>
20
+ <div class="distance">2</div>
21
+ <div class="corner">3</div>
22
+ <div>4</div>
23
+ <div class="center">5</div>
24
+ <div>6</div>
25
+ <div class="corner">7</div>
26
+ <div>8</div>
27
+ <div class="corner">9</div>
28
+ <div class="footer distance">10</div>
29
+ </body>
30
+ </html>
31
+
@@ -6,7 +6,26 @@
6
6
  <script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
7
7
  <script src="/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
8
8
  <script src="/test.js" type="text/javascript" charset="utf-8"></script>
9
+ <script type="text/javascript">
10
+ $(document).on('transitionend', function(){
11
+ $(document.body).append('<div>Transition Ended</div>')
12
+ });
13
+ $(document).on('animationend', function(){
14
+ $(document.body).append('<div>Animation Ended</div>')
15
+ });
16
+ $(document).on('contextmenu', function(e){
17
+ e.preventDefault();
18
+ });
19
+ </script>
9
20
  <style>
21
+ html {
22
+ scroll-behavior: smooth;
23
+ }
24
+
25
+ body {
26
+ min-height: 2000px;
27
+ }
28
+
10
29
  .transition.away {
11
30
  width: 0%;
12
31
  }
@@ -17,6 +36,13 @@
17
36
  overflow: hidden;
18
37
  }
19
38
 
39
+ a::after {
40
+ content: "";
41
+ width: 0px;
42
+ height: 0px;
43
+ background-color: blue;
44
+ }
45
+
20
46
  a:not(.away) {
21
47
  height: 20px;
22
48
  }
@@ -35,12 +61,22 @@
35
61
  animation-duration: 3s;
36
62
  animation-fill-mode: forwards;
37
63
  }
64
+
65
+ @keyframes pseudo_grow {
66
+ 100% { height: 100px, width: 100px };
67
+ }
68
+
69
+ a.animation.pseudo::after {
70
+ animation: pseudo_grow 3s forwards;
71
+ }
38
72
  </style>
39
73
  </head>
40
74
 
41
75
  <body id="with_animation">
42
76
  <a href='#' class='transition' onclick='this.classList.add("away")'>transition me away</a>
43
- <a href='#' class='animation' onclick='this.classList.add("away")'>animate me away</a>
77
+ <a href='#' class='animation' onclick='this.classList.add("away")' oncontextmenu='this.classList.add("pseudo")'>
78
+ animate me away
79
+ </a>
44
80
  </body>
45
81
  </html>
46
82
 
@@ -0,0 +1,24 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
+ <title>with_dragula</title>
5
+
6
+ </head>
7
+
8
+ <body id="with_dragula">
9
+ <div id="sortable">
10
+ <div class="item1">Item 1</div>
11
+ <div class="item2">Item 2</div>
12
+ <div class="item3">Item 3</div>
13
+ <div class="item4">Item 4</div>
14
+ <div class="item5">Item 5</div>
15
+ </div>
16
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.2/dragula.js" type="text/javascript"></script>
17
+ <script>
18
+ let container = document.getElementById("sortable");
19
+ dragula([container]);
20
+ container.className = "ready"
21
+ </script>
22
+ </body>
23
+ </html>
24
+
@@ -36,8 +36,8 @@
36
36
  </p>
37
37
 
38
38
  <p>
39
- <input type="text" id="test_field" data-test-id="test_id" value="monkey"/>
40
- <input type="text" readonly="readonly" value="should not change" />
39
+ <input type="text" id="test_field" spellcheck="TRUE" data-test-id="test_id" value="monkey"/>
40
+ <input type="text" readonly="readonly" spellcheck="FALSE" value="should not change" />
41
41
  <textarea id="normal" data-other-test-id="test_id">
42
42
  banana</textarea>
43
43
  <textarea id="additional_newline">
@@ -138,6 +138,9 @@ banana</textarea>
138
138
  Ancestor
139
139
  <div id="child">Child</div>
140
140
  </div>
141
+ <div id="ancestor1_sibiling">
142
+ ASibling
143
+ </div>
141
144
  </div>
142
145
  <button id="ancestor_button" type="submit" disabled>
143
146
  <img id="button_img" width="20" height="20" alt="button img"/>
@@ -178,6 +181,25 @@ banana</textarea>
178
181
  &#x20;&#x1680;&#x2000;&#x2001;&#x2002; &#x2003;&#x2004;&nbsp;&#x2005; &#x2006;&#x2007;&#x2008;&#x2009;&#x200A;&#x202F;&#x205F;&#x3000;
179
182
  </div>
180
183
 
184
+ <details id="closed_details">
185
+ <summary>
186
+ <h6>Something</h6>
187
+ </summary>
188
+ <ul>
189
+ <li>Random</li>
190
+ <li>Things</li>
191
+ </ul>
192
+ </details>
193
+
194
+ <details id="open_details" open>
195
+ <summary>
196
+ <h6>Summary</h6>
197
+ </summary>
198
+ <div>
199
+ Contents
200
+ </div>
201
+ </details>
202
+
181
203
  <template id="template">
182
204
  <input />
183
205
  </template>
@@ -0,0 +1,24 @@
1
+
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5
+ <title>with_jquery_animation</title>
6
+ <style>
7
+ body {
8
+ height: 2000px;
9
+ }
10
+ </style>
11
+ </head>
12
+
13
+ <body id="with_animation">
14
+ <a href="#" id='scroll'>scroll top 500</a>
15
+
16
+ <script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
17
+ <script type='text/javascript'>
18
+ $('#scroll').click(function(e){
19
+ e.preventDefault();
20
+ $('html, body').animate({ scrollTop: 500 }, 'slow');
21
+ });
22
+ </script>
23
+ </body>
24
+ </html>
@@ -28,13 +28,15 @@
28
28
  <div id="drag_html5" draggable="true">
29
29
  <p>This is an HTML5 draggable element.</p>
30
30
  </div>
31
- <a id="drag_link_html5" href="#">This is an HTML5 draggable link</a>
31
+ <a id="drag_link_html5" href="#"><p>This is an HTML5 draggable link</p></a>
32
32
  <div id="drop_html5" class="drop">
33
33
  <p>It should be dropped here.</p>
34
34
  </div>
35
35
 
36
36
  <p><a href="#" id="clickable">Click me</a></p>
37
37
  <p><a href="#" id="slow-click">Slowly</a></p>
38
+ <p><span id="aria-button" role="button">ARIA button</span></p>
39
+ <p><span role="button">ARIA button2</span></p>
38
40
 
39
41
  <p>
40
42
  <select id="waiter">
@@ -151,6 +153,7 @@
151
153
  <p>This is an HTML5 draggable element.</p>
152
154
  </div>
153
155
 
156
+ <div id="shadow"></div>
154
157
  <script type="text/javascript">
155
158
  // a javascript comment
156
159
  var aVar = 123;
@@ -0,0 +1,26 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5
+ <title>with_jstree</title>
6
+ </head>
7
+ <body id="with_jstree">
8
+ <div id="container">
9
+ <ul>
10
+ <li>Child node A</li>
11
+ <li>Child node B</li>
12
+ <li>Child node C</li>
13
+ </ul>
14
+ </div>
15
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
16
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
17
+ <script>
18
+ $(function () {
19
+ $('#container').jstree({
20
+ "core" : { "check_callback" : true }, // so that operations work
21
+ "plugins" : ["dnd"]
22
+ });
23
+ });
24
+ </script>
25
+ </body>
26
+ </html>
@@ -2,7 +2,7 @@
2
2
  <head>
3
3
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4
4
  <title>with_sortable_js</title>
5
- <script src="https://sortablejs.github.io/Sortable/Sortable.js" type="text/javascript"></script>
5
+ <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.12.0/dist/sortable.umd.min.js" type="text/javascript"></script>
6
6
  </head>
7
7
 
8
8
  <body id="with_sortable_js">
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Capybara
4
- VERSION = '3.23.0'
4
+ VERSION = '3.35.3'
5
5
  end
@@ -4,7 +4,7 @@ module Capybara
4
4
  ##
5
5
  # The {Window} class represents a browser window.
6
6
  #
7
- # You can get an instance of the class by calling either of:
7
+ # You can get an instance of the class by calling any of:
8
8
  #
9
9
  # * {Capybara::Session#windows}
10
10
  # * {Capybara::Session#current_window}
@@ -82,8 +82,8 @@ module Capybara
82
82
  # Resize window.
83
83
  #
84
84
  # @macro about_current
85
- # @param width [String] the new window width in pixels
86
- # @param height [String] the new window height in pixels
85
+ # @param width [Integer] the new window width in pixels
86
+ # @param height [Integer] the new window height in pixels
87
87
  #
88
88
  def resize_to(width, height)
89
89
  wait_for_stable_size { @driver.resize_window_to(handle, width, height) }
@@ -138,9 +138,5 @@ module Capybara
138
138
  end
139
139
  raise Capybara::WindowError, "Window size not stable within #{seconds} seconds."
140
140
  end
141
-
142
- def raise_unless_current(what)
143
- raise Capybara::WindowError, "#{what} not current window is not possible." unless current?
144
- end
145
141
  end
146
142
  end
@@ -3,9 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Capybara do
6
+ include Capybara::RSpecMatchers
6
7
  describe '.string' do
7
8
  let :string do
8
- Capybara.string <<-STRING
9
+ described_class.string <<-STRING
9
10
  <html>
10
11
  <head>
11
12
  <title>simple_node</title>
@@ -52,7 +53,7 @@ RSpec.describe Capybara do
52
53
  end
53
54
 
54
55
  it 'allows using custom matchers' do
55
- Capybara.add_selector :lifeform do
56
+ described_class.add_selector :lifeform do
56
57
  xpath { |name| ".//option[contains(.,'#{name}')]" }
57
58
  end
58
59
  expect(string).to have_selector(:id, 'page')
@@ -62,7 +63,7 @@ RSpec.describe Capybara do
62
63
  end
63
64
 
64
65
  it 'allows custom matcher using css' do
65
- Capybara.add_selector :section do
66
+ described_class.add_selector :section do
66
67
  css { |css_class| "section .#{css_class}" }
67
68
  end
68
69
  expect(string).to have_selector(:section, 'subsection')
@@ -112,13 +113,13 @@ RSpec.describe Capybara do
112
113
 
113
114
  it 'drops illegal fragments when using gumbo' do
114
115
  skip 'libxml is less strict than Gumbo' unless Nokogiri.respond_to?(:HTML5)
115
- expect(Capybara.string('<td>1</td>')).not_to have_css('td')
116
+ expect(described_class.string('<td>1</td>')).not_to have_css('td')
116
117
  end
117
118
 
118
119
  it 'can disable use of gumbo' do
119
120
  skip "Test doesn't make sense unlesss nokogumbo is loaded" unless Nokogiri.respond_to?(:HTML5)
120
- Capybara.allow_gumbo = false
121
- expect(Capybara.string('<td>1</td>')).to have_css('td')
121
+ described_class.allow_gumbo = false
122
+ expect(described_class.string('<td>1</td>')).to have_css('td')
122
123
  end
123
124
 
124
125
  describe '#title' do
@@ -129,25 +130,25 @@ RSpec.describe Capybara do
129
130
 
130
131
  describe '#has_title?' do
131
132
  it 'returns whether the page has the given title' do
132
- expect(string.has_title?('simple_node')).to be_truthy
133
- expect(string.has_title?('monkey')).to be_falsey
133
+ expect(string.has_title?('simple_node')).to be true
134
+ expect(string.has_title?('monkey')).to be false
134
135
  end
135
136
 
136
137
  it 'allows regexp matches' do
137
- expect(string.has_title?(/s[a-z]+_node/)).to be_truthy
138
- expect(string.has_title?(/monkey/)).to be_falsey
138
+ expect(string.has_title?(/s[a-z]+_node/)).to be true
139
+ expect(string.has_title?(/monkey/)).to be false
139
140
  end
140
141
  end
141
142
 
142
143
  describe '#has_no_title?' do
143
144
  it 'returns whether the page does not have the given title' do
144
- expect(string.has_no_title?('simple_node')).to be_falsey
145
- expect(string.has_no_title?('monkey')).to be_truthy
145
+ expect(string.has_no_title?('simple_node')).to be false
146
+ expect(string.has_no_title?('monkey')).to be true
146
147
  end
147
148
 
148
149
  it 'allows regexp matches' do
149
- expect(string.has_no_title?(/s[a-z]+_node/)).to be_falsey
150
- expect(string.has_no_title?(/monkey/)).to be_truthy
150
+ expect(string.has_no_title?(/s[a-z]+_node/)).to be false
151
+ expect(string.has_no_title?(/monkey/)).to be true
151
152
  end
152
153
  end
153
154
  end
@@ -4,20 +4,20 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Capybara do
6
6
  describe 'default_max_wait_time' do
7
- before { @previous_default_time = Capybara.default_max_wait_time }
7
+ before { @previous_default_time = described_class.default_max_wait_time }
8
8
 
9
- after { Capybara.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
9
+ after { described_class.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
10
10
 
11
11
  it 'should be changeable' do
12
- expect(Capybara.default_max_wait_time).not_to eq(5)
13
- Capybara.default_max_wait_time = 5
14
- expect(Capybara.default_max_wait_time).to eq(5)
12
+ expect(described_class.default_max_wait_time).not_to eq(5)
13
+ described_class.default_max_wait_time = 5
14
+ expect(described_class.default_max_wait_time).to eq(5)
15
15
  end
16
16
  end
17
17
 
18
18
  describe '.register_driver' do
19
19
  it 'should add a new driver' do
20
- Capybara.register_driver :schmoo do |app|
20
+ described_class.register_driver :schmoo do |app|
21
21
  Capybara::RackTest::Driver.new(app)
22
22
  end
23
23
  session = Capybara::Session.new(:schmoo, TestApp)
@@ -28,85 +28,85 @@ RSpec.describe Capybara do
28
28
 
29
29
  describe '.register_server' do
30
30
  it 'should add a new server' do
31
- Capybara.register_server :blob do |_app, _port, _host|
31
+ described_class.register_server :blob do |_app, _port, _host|
32
32
  # do nothing
33
33
  end
34
34
 
35
- expect(Capybara.servers).to have_key(:blob)
35
+ expect(described_class.servers[:blob]).to be_truthy
36
36
  end
37
37
  end
38
38
 
39
39
  describe '.server' do
40
40
  after do
41
- Capybara.server = :default
41
+ described_class.server = :default
42
42
  end
43
43
 
44
44
  it 'should default to a proc that calls run_default_server' do
45
45
  mock_app = Object.new
46
- allow(Capybara).to receive(:run_default_server).and_return(true)
47
- Capybara.server.call(mock_app, 8000)
48
- expect(Capybara).to have_received(:run_default_server).with(mock_app, 8000)
46
+ allow(described_class).to receive(:run_default_server).and_return(true)
47
+ described_class.server.call(mock_app, 8000)
48
+ expect(described_class).to have_received(:run_default_server).with(mock_app, 8000)
49
49
  end
50
50
 
51
51
  it 'should return a custom server proc' do
52
52
  server = ->(_app, _port) {}
53
- Capybara.register_server :custom, &server
54
- Capybara.server = :custom
55
- expect(Capybara.server).to eq(server)
53
+ described_class.register_server :custom, &server
54
+ described_class.server = :custom
55
+ expect(described_class.server).to eq(server)
56
56
  end
57
57
 
58
58
  it 'should have :webrick registered' do
59
- expect(Capybara.servers[:webrick]).not_to be_nil
59
+ expect(described_class.servers[:webrick]).not_to be_nil
60
60
  end
61
61
 
62
62
  it 'should have :puma registered' do
63
- expect(Capybara.servers[:puma]).not_to be_nil
63
+ expect(described_class.servers[:puma]).not_to be_nil
64
64
  end
65
65
  end
66
66
 
67
67
  describe 'server=' do
68
68
  after do
69
- Capybara.server = :default
69
+ described_class.server = :default
70
70
  end
71
71
 
72
72
  it 'accepts a proc' do
73
73
  server = ->(_app, _port) {}
74
- Capybara.server = server
75
- expect(Capybara.server).to eq server
74
+ described_class.server = server
75
+ expect(described_class.server).to eq server
76
76
  end
77
77
  end
78
78
 
79
79
  describe 'app_host' do
80
80
  after do
81
- Capybara.app_host = nil
81
+ described_class.app_host = nil
82
82
  end
83
83
 
84
84
  it 'should warn if not a valid URL' do
85
- expect { Capybara.app_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.app_host should be set to a url/)
85
+ expect { described_class.app_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.app_host should be set to a url/)
86
86
  end
87
87
 
88
88
  it 'should not warn if a valid URL' do
89
- expect { Capybara.app_host = 'http://www.example.com' }.not_to raise_error
89
+ expect { described_class.app_host = 'http://www.example.com' }.not_to raise_error
90
90
  end
91
91
 
92
92
  it 'should not warn if nil' do
93
- expect { Capybara.app_host = nil }.not_to raise_error
93
+ expect { described_class.app_host = nil }.not_to raise_error
94
94
  end
95
95
  end
96
96
 
97
97
  describe 'default_host' do
98
98
  around do |test|
99
- old_default = Capybara.default_host
99
+ old_default = described_class.default_host
100
100
  test.run
101
- Capybara.default_host = old_default
101
+ described_class.default_host = old_default
102
102
  end
103
103
 
104
104
  it 'should raise if not a valid URL' do
105
- expect { Capybara.default_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
105
+ expect { described_class.default_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
106
106
  end
107
107
 
108
108
  it 'should not warn if a valid URL' do
109
- expect { Capybara.default_host = 'http://www.example.com' }.not_to raise_error
109
+ expect { described_class.default_host = 'http://www.example.com' }.not_to raise_error
110
110
  end
111
111
  end
112
112
  end