capybara 2.18.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +26 -1
  3. data/README.md +12 -12
  4. data/lib/capybara.rb +13 -25
  5. data/lib/capybara/config.rb +11 -57
  6. data/lib/capybara/cucumber.rb +2 -3
  7. data/lib/capybara/driver/base.rb +5 -16
  8. data/lib/capybara/driver/node.rb +5 -4
  9. data/lib/capybara/dsl.rb +1 -0
  10. data/lib/capybara/helpers.rb +16 -28
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/minitest/spec.rb +15 -14
  13. data/lib/capybara/node/actions.rb +59 -81
  14. data/lib/capybara/node/base.rb +11 -18
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +8 -8
  17. data/lib/capybara/node/element.rb +30 -40
  18. data/lib/capybara/node/finders.rb +62 -70
  19. data/lib/capybara/node/matchers.rb +48 -71
  20. data/lib/capybara/node/simple.rb +11 -17
  21. data/lib/capybara/queries/ancestor_query.rb +4 -6
  22. data/lib/capybara/queries/base_query.rb +18 -17
  23. data/lib/capybara/queries/current_path_query.rb +8 -24
  24. data/lib/capybara/queries/match_query.rb +3 -7
  25. data/lib/capybara/queries/selector_query.rb +92 -95
  26. data/lib/capybara/queries/sibling_query.rb +4 -4
  27. data/lib/capybara/queries/text_query.rb +37 -34
  28. data/lib/capybara/queries/title_query.rb +8 -11
  29. data/lib/capybara/rack_test/browser.rb +15 -18
  30. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  31. data/lib/capybara/rack_test/driver.rb +6 -10
  32. data/lib/capybara/rack_test/form.rb +50 -40
  33. data/lib/capybara/rack_test/node.rb +70 -56
  34. data/lib/capybara/rails.rb +2 -6
  35. data/lib/capybara/result.rb +22 -22
  36. data/lib/capybara/rspec.rb +5 -10
  37. data/lib/capybara/rspec/compound.rb +5 -10
  38. data/lib/capybara/rspec/features.rb +17 -48
  39. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  40. data/lib/capybara/rspec/matchers.rb +70 -60
  41. data/lib/capybara/selector.rb +129 -117
  42. data/lib/capybara/selector/css.rb +6 -11
  43. data/lib/capybara/selector/filter.rb +1 -17
  44. data/lib/capybara/selector/filter_set.rb +17 -14
  45. data/lib/capybara/selector/filters/base.rb +7 -6
  46. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  47. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  48. data/lib/capybara/selector/selector.rb +27 -33
  49. data/lib/capybara/selenium/driver.rb +113 -127
  50. data/lib/capybara/selenium/node.rb +148 -113
  51. data/lib/capybara/server.rb +3 -2
  52. data/lib/capybara/session.rb +137 -223
  53. data/lib/capybara/session/config.rb +47 -67
  54. data/lib/capybara/session/matchers.rb +8 -7
  55. data/lib/capybara/spec/public/test.js +26 -4
  56. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  57. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  58. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  59. data/lib/capybara/spec/session/all_spec.rb +31 -18
  60. data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
  61. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  62. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  63. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  64. data/lib/capybara/spec/session/assert_text.rb +18 -17
  65. data/lib/capybara/spec/session/assert_title.rb +1 -0
  66. data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
  67. data/lib/capybara/spec/session/body_spec.rb +1 -0
  68. data/lib/capybara/spec/session/check_spec.rb +7 -6
  69. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  70. data/lib/capybara/spec/session/click_button_spec.rb +20 -28
  71. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  72. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  73. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  74. data/lib/capybara/spec/session/current_url_spec.rb +7 -6
  75. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  76. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  77. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  78. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  79. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  80. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  81. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  83. data/lib/capybara/spec/session/fill_in_spec.rb +6 -5
  84. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  85. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  86. data/lib/capybara/spec/session/find_field_spec.rb +8 -14
  87. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  88. data/lib/capybara/spec/session/find_spec.rb +37 -31
  89. data/lib/capybara/spec/session/first_spec.rb +60 -33
  90. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  91. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  92. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  93. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  94. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  95. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  96. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  97. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  98. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  99. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  100. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  101. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  102. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  103. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  104. data/lib/capybara/spec/session/has_text_spec.rb +6 -5
  105. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  106. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  107. data/lib/capybara/spec/session/headers.rb +2 -1
  108. data/lib/capybara/spec/session/html_spec.rb +1 -0
  109. data/lib/capybara/spec/session/node_spec.rb +91 -56
  110. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  111. data/lib/capybara/spec/session/refresh_spec.rb +4 -2
  112. data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
  113. data/lib/capybara/spec/session/response_code.rb +1 -0
  114. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  116. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  117. data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
  118. data/lib/capybara/spec/session/select_spec.rb +20 -20
  119. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  120. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  121. data/lib/capybara/spec/session/text_spec.rb +1 -0
  122. data/lib/capybara/spec/session/title_spec.rb +1 -1
  123. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  124. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  125. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  126. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  127. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  128. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  130. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  132. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  133. data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
  134. data/lib/capybara/spec/session/within_spec.rb +1 -0
  135. data/lib/capybara/spec/spec_helper.rb +26 -18
  136. data/lib/capybara/spec/test_app.rb +8 -9
  137. data/lib/capybara/spec/views/form.erb +1 -0
  138. data/lib/capybara/spec/views/with_html.erb +3 -1
  139. data/lib/capybara/spec/views/within_frames.erb +4 -1
  140. data/lib/capybara/version.rb +2 -1
  141. data/lib/capybara/window.rb +6 -10
  142. data/spec/basic_node_spec.rb +1 -0
  143. data/spec/capybara_spec.rb +9 -32
  144. data/spec/dsl_spec.rb +5 -13
  145. data/spec/filter_set_spec.rb +5 -4
  146. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  147. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  148. data/spec/minitest_spec.rb +4 -3
  149. data/spec/minitest_spec_spec.rb +3 -2
  150. data/spec/per_session_config_spec.rb +9 -8
  151. data/spec/rack_test_spec.rb +21 -20
  152. data/spec/result_spec.rb +17 -16
  153. data/spec/rspec/features_spec.rb +17 -14
  154. data/spec/rspec/scenarios_spec.rb +5 -7
  155. data/spec/rspec/shared_spec_matchers.rb +96 -99
  156. data/spec/rspec/views_spec.rb +2 -1
  157. data/spec/rspec_matchers_spec.rb +19 -2
  158. data/spec/rspec_spec.rb +11 -15
  159. data/spec/selector_spec.rb +5 -6
  160. data/spec/selenium_spec_chrome.rb +7 -4
  161. data/spec/selenium_spec_marionette.rb +26 -12
  162. data/spec/server_spec.rb +33 -33
  163. data/spec/session_spec.rb +2 -1
  164. data/spec/shared_selenium_session.rb +27 -21
  165. data/spec/spec_helper.rb +2 -5
  166. metadata +66 -87
  167. data/lib/capybara/query.rb +0 -7
  168. data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,61 +1,55 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'delegate'
3
4
 
4
5
  module Capybara
5
6
  class SessionConfig
6
- OPTIONS = [:always_include_port, :run_server, :default_selector, :default_max_wait_time, :ignore_hidden_elements,
7
- :automatic_reload, :match, :exact, :exact_text, :raise_server_errors, :visible_text_only, :wait_on_first_by_default,
8
- :automatic_label_click, :enable_aria_label, :save_path, :exact_options, :asset_host, :default_host, :app_host,
9
- :save_and_open_page_path, :server_host, :server_port, :server_errors]
7
+ OPTIONS = %i[always_include_port run_server default_selector default_max_wait_time ignore_hidden_elements
8
+ automatic_reload match exact exact_text raise_server_errors visible_text_only
9
+ automatic_label_click enable_aria_label save_path asset_host default_host app_host
10
+ server_host server_port server_errors].freeze
10
11
 
11
12
  attr_accessor(*OPTIONS)
12
13
 
13
14
  ##
14
- #@!method always_include_port
15
- # See {Capybara.configure}
16
- #@!method run_server
17
- # See {Capybara.configure}
18
- #@!method default_selector
19
- # See {Capybara.configure}
20
- #@!method default_max_wait_time
21
- # See {Capybara.configure}
22
- #@!method ignore_hidden_elements
23
- # See {Capybara.configure}
24
- #@!method automatic_reload
25
- # See {Capybara.configure}
26
- #@!method match
27
- # See {Capybara.configure}
28
- #@!method exact
29
- # See {Capybara.configure}
30
- #@!method raise_server_errors
31
- # See {Capybara.configure}
32
- #@!method visible_text_only
33
- # See {Capybara.configure}
34
- #@!method wait_on_first_by_default
35
- # See {Capybara.configure}
36
- #@!method automatic_label_click
37
- # See {Capybara.configure}
38
- #@!method enable_aria_label
39
- # See {Capybara.configure}
40
- #@!method save_path
41
- # See {Capybara.configure}
42
- #@deprecated
43
- #@!method exact_options
44
- # See {Capybara.configure}
45
- #@!method asset_host
46
- # See {Capybara.configure}
47
- #@!method default_host
48
- # See {Capybara.configure}
49
- #@!method app_host
50
- # See {Capybara.configure}
51
- #@!method save_and_open_page_path
52
- # See {Capybara.configure}
53
- #@!method server_host
54
- # See {Capybara.configure}
55
- #@!method server_port
56
- # See {Capybara.configure}
57
- #@!method server_errors
58
- # See {Capybara.configure}
15
+ # @!method always_include_port
16
+ # See {Capybara.configure}
17
+ # @!method run_server
18
+ # See {Capybara.configure}
19
+ # @!method default_selector
20
+ # See {Capybara.configure}
21
+ # @!method default_max_wait_time
22
+ # See {Capybara.configure}
23
+ # @!method ignore_hidden_elements
24
+ # See {Capybara.configure}
25
+ # @!method automatic_reload
26
+ # See {Capybara.configure}
27
+ # @!method match
28
+ # See {Capybara.configure}
29
+ # @!method exact
30
+ # See {Capybara.configure}
31
+ # @!method raise_server_errors
32
+ # See {Capybara.configure}
33
+ # @!method visible_text_only
34
+ # See {Capybara.configure}
35
+ # @!method automatic_label_click
36
+ # See {Capybara.configure}
37
+ # @!method enable_aria_label
38
+ # See {Capybara.configure}
39
+ # @!method save_path
40
+ # See {Capybara.configure}
41
+ # @!method asset_host
42
+ # See {Capybara.configure}
43
+ # @!method default_host
44
+ # See {Capybara.configure}
45
+ # @!method app_host
46
+ # See {Capybara.configure}
47
+ # @!method server_host
48
+ # See {Capybara.configure}
49
+ # @!method server_port
50
+ # See {Capybara.configure}
51
+ # @!method server_errors
52
+ # See {Capybara.configure}
59
53
 
60
54
  remove_method :server_host
61
55
 
@@ -74,30 +68,16 @@ module Capybara
74
68
 
75
69
  remove_method :app_host=
76
70
  def app_host=(url)
77
- raise ArgumentError.new("Capybara.app_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::Parser.new.make_regexp)
71
+ raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
78
72
  @app_host = url
79
73
  end
80
74
 
81
75
  remove_method :default_host=
82
76
  def default_host=(url)
83
- raise ArgumentError.new("Capybara.default_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::Parser.new.make_regexp)
77
+ raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
84
78
  @default_host = url
85
79
  end
86
80
 
87
- remove_method :save_and_open_page_path=
88
- def save_and_open_page_path=(path)
89
- warn "DEPRECATED: #save_and_open_page_path is deprecated, please use #save_path instead. \n"\
90
- "Note: Behavior is slightly different with relative paths - see documentation" unless path.nil?
91
- @save_and_open_page_path = path
92
- end
93
-
94
- remove_method :exact_options=
95
- def exact_options=(opt)
96
- @exact_options = opt
97
- warn "DEPRECATED: #exact_options is deprecated, please scope your findes/actions and use the `:exact` "\
98
- "option if similar functionality is needed."
99
- end
100
-
101
81
  def initialize_copy(other)
102
82
  super
103
83
  @server_errors = @server_errors.dup
@@ -106,9 +86,9 @@ module Capybara
106
86
 
107
87
  class ReadOnlySessionConfig < SimpleDelegator
108
88
  SessionConfig::OPTIONS.each do |m|
109
- define_method "#{m}=" do |val|
89
+ define_method "#{m}=" do |_|
110
90
  raise "Per session settings are only supported when Capybara.threadsafe == true"
111
91
  end
112
92
  end
113
93
  end
114
- end
94
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Capybara
3
4
  module SessionMatchers
4
5
  ##
@@ -18,8 +19,8 @@ module Capybara
18
19
  # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
19
20
  # @return [true]
20
21
  #
21
- def assert_current_path(path, options={})
22
- _verify_current_path(path,options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
22
+ def assert_current_path(path, **options)
23
+ _verify_current_path(path, options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
23
24
  end
24
25
 
25
26
  ##
@@ -32,8 +33,8 @@ module Capybara
32
33
  # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
33
34
  # @return [true]
34
35
  #
35
- def assert_no_current_path(path, options={})
36
- _verify_current_path(path,options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
36
+ def assert_no_current_path(path, **options)
37
+ _verify_current_path(path, options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
37
38
  end
38
39
 
39
40
  ##
@@ -45,7 +46,7 @@ module Capybara
45
46
  # @macro current_path_query_params
46
47
  # @return [Boolean]
47
48
  #
48
- def has_current_path?(path, options={})
49
+ def has_current_path?(path, **options)
49
50
  assert_current_path(path, options)
50
51
  rescue Capybara::ExpectationNotMet
51
52
  return false
@@ -60,13 +61,13 @@ module Capybara
60
61
  # @macro current_path_query_params
61
62
  # @return [Boolean]
62
63
  #
63
- def has_no_current_path?(path, options={})
64
+ def has_no_current_path?(path, **options)
64
65
  assert_no_current_path(path, options)
65
66
  rescue Capybara::ExpectationNotMet
66
67
  return false
67
68
  end
68
69
 
69
- private
70
+ private
70
71
 
71
72
  def _verify_current_path(path, options)
72
73
  query = Capybara::Queries::CurrentPathQuery.new(path, options)
@@ -8,7 +8,8 @@ $(function() {
8
8
  $(this).html('Dropped!');
9
9
  }
10
10
  });
11
- $('#clickable').click(function() {
11
+ $('#clickable').click(function(e) {
12
+ debugger;
12
13
  var link = $(this);
13
14
  setTimeout(function() {
14
15
  $(link).after('<a id="has-been-clicked" href="#">Has been clicked</a>');
@@ -64,12 +65,33 @@ $(function() {
64
65
  }, 400)
65
66
  });
66
67
  $('#click-test').on({
67
- dblclick: function() {
68
- $(this).after('<a id="has-been-double-clicked" href="#">Has been double clicked</a>');
68
+ click: function(e) {
69
+ var desc = "";
70
+ if (e.altKey) desc += 'alt ';
71
+ if (e.ctrlKey) desc += 'control ';
72
+ if (e.metaKey) desc += 'meta ';
73
+ if (e.shiftKey) desc += 'shift ';
74
+ var pos = this.getBoundingClientRect();
75
+ $(this).after('<a id="has-been-clicked" href="#">Has been ' + desc + 'clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
76
+ },
77
+ dblclick: function(e) {
78
+ var desc = "";
79
+ if (e.altKey) desc += 'alt ';
80
+ if (e.ctrlKey) desc += 'control ';
81
+ if (e.metaKey) desc += 'meta ';
82
+ if (e.shiftKey) desc += 'shift ';
83
+ var pos = this.getBoundingClientRect();
84
+ $(this).after('<a id="has-been-double-clicked" href="#">Has been ' + desc + 'double clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
69
85
  },
70
86
  contextmenu: function(e) {
71
87
  e.preventDefault();
72
- $(this).after('<a id="has-been-right-clicked" href="#">Has been right clicked</a>');
88
+ var desc = "";
89
+ if (e.altKey) desc += 'alt ';
90
+ if (e.ctrlKey) desc += 'control ';
91
+ if (e.metaKey) desc += 'meta ';
92
+ if (e.shiftKey) desc += 'shift ';
93
+ var pos = this.getBoundingClientRect();
94
+ $(this).after('<a id="has-been-right-clicked" href="#">Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
73
95
  }
74
96
  });
75
97
  $('#open-alert').click(function() {
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -19,13 +20,13 @@ Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
19
20
  end
20
21
 
21
22
  it "should work with nested modals" do
22
- expect {
23
+ expect do
23
24
  @session.dismiss_confirm 'Are you really sure?' do
24
25
  @session.accept_confirm 'Are you sure?' do
25
26
  @session.click_link('Open check twice')
26
27
  end
27
28
  end
28
- }.not_to raise_error
29
+ end.not_to raise_error
29
30
  expect(@session).to have_xpath("//a[@id='open-twice' and @confirmed='false']")
30
31
  end
31
32
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#all" do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -14,11 +15,23 @@ Capybara::SpecHelper.spec "#all" do
14
15
  expect(@session.all('//div[@id="nosuchthing"]')).to be_empty
15
16
  end
16
17
 
17
- it "should accept an XPath instance" do
18
+ it "should wait for matching elements to appear", requires: [:js] do
19
+ @session.visit('/with_js')
20
+ @session.click_link('Click me')
21
+ expect(@session.all(:css, "a#has-been-clicked")).not_to be_empty
22
+ end
23
+
24
+ it "should not wait if `minimum: 0` option is specified", requires: [:js] do
25
+ @session.visit('/with_js')
26
+ @session.click_link('Click me')
27
+ expect(@session.all(:css, "a#has-been-clicked", minimum: 0)).to be_empty
28
+ end
29
+
30
+ it "should accept an XPath instance", :exact_false do
18
31
  @session.visit('/form')
19
32
  @xpath = Capybara::Selector.all[:fillable_field].call('Name')
20
33
  expect(@xpath).to be_a(::XPath::Union)
21
- @result = @session.all(@xpath).map { |r| r.value }
34
+ @result = @session.all(@xpath).map(&:value)
22
35
  expect(@result).to include('Smith', 'John', 'John Smith')
23
36
  end
24
37
 
@@ -116,35 +129,35 @@ Capybara::SpecHelper.spec "#all" do
116
129
 
117
130
  context 'with multiple count filters' do
118
131
  it 'ignores other filters when :count is specified' do
119
- o = {count: 4,
120
- minimum: 5,
121
- maximum: 0,
122
- between: 0..3}
132
+ o = { count: 4,
133
+ minimum: 5,
134
+ maximum: 0,
135
+ between: 0..3 }
123
136
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
124
137
  end
125
138
  context 'with no :count expectation' do
126
139
  it 'fails if :minimum is not met' do
127
- o = {minimum: 5,
128
- maximum: 4,
129
- between: 2..7}
140
+ o = { minimum: 5,
141
+ maximum: 4,
142
+ between: 2..7 }
130
143
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
131
144
  end
132
145
  it 'fails if :maximum is not met' do
133
- o = {minimum: 0,
134
- maximum: 0,
135
- between: 2..7}
146
+ o = { minimum: 0,
147
+ maximum: 0,
148
+ between: 2..7 }
136
149
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
137
150
  end
138
151
  it 'fails if :between is not met' do
139
- o = {minimum: 0,
140
- maximum: 4,
141
- between: 0..3}
152
+ o = { minimum: 0,
153
+ maximum: 4,
154
+ between: 0..3 }
142
155
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
143
156
  end
144
157
  it 'succeeds if all combineable expectations are met' do
145
- o = {minimum: 0,
146
- maximum: 4,
147
- between: 2..7}
158
+ o = { minimum: 0,
159
+ maximum: 4,
160
+ between: 2..7 }
148
161
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
149
162
  end
150
163
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#ancestor' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -57,7 +58,6 @@ Capybara::SpecHelper.spec '#ancestor' do
57
58
  end
58
59
  end
59
60
 
60
-
61
61
  it "should raise ElementNotFound with a useful default message if nothing was found" do
62
62
  el = @session.find(:css, '#child')
63
63
  expect do
@@ -65,13 +65,11 @@ Capybara::SpecHelper.spec '#ancestor' do
65
65
  end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is an ancestor of visible css \"#child\"")
66
66
  end
67
67
 
68
-
69
-
70
68
  context "within a scope" do
71
69
  it "should limit the ancestors to inside the scope" do
72
70
  @session.within(:css, '#ancestor2') do
73
71
  el = @session.find(:css, '#child')
74
- expect(el.ancestor(:css,'div', text: 'Ancestor')[:id]).to eq('ancestor1')
72
+ expect(el.ancestor(:css, 'div', text: 'Ancestor')[:id]).to eq('ancestor1')
75
73
  end
76
74
  end
77
75
  end
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_all_of_selectors' do
3
4
  before do
4
5
  @session.visit('/with_html')
5
6
  end
6
7
 
7
8
  it "should be true if the given selectors are on the page" do
8
- @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two" )
9
+ @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
9
10
  end
10
11
 
11
12
  it "should be false if any of the given selectors are not on the page" do
12
- expect { @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
13
+ expect { @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one") }.to raise_error(Capybara::ElementNotFound)
13
14
  end
14
15
 
15
16
  it "should use default selector" do
16
17
  Capybara.default_selector = :css
17
- expect { @session.assert_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
18
- @session.assert_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one" )
18
+ expect { @session.assert_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one") }.to raise_error(Capybara::ElementNotFound)
19
+ @session.assert_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one")
19
20
  end
20
21
 
21
22
  context "should respect scopes" do
@@ -63,7 +64,7 @@ Capybara::SpecHelper.spec '#assert_none_of_selectors' do
63
64
  end
64
65
 
65
66
  it "should be true if none of the given locators are on the page" do
66
- @session.assert_none_of_selectors(:xpath, "//abbr", "//td" )
67
+ @session.assert_none_of_selectors(:xpath, "//abbr", "//td")
67
68
  @session.assert_none_of_selectors(:css, "p a#doesnotexist", "abbr")
68
69
  end
69
70
 
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_current_path' do
3
4
  before do
4
5
  @session.visit('/with_js')
5
6
  end
6
7
 
7
8
  it "should not raise if the page has the given current path" do
8
- expect {@session.assert_current_path('/with_js')}.not_to raise_error
9
+ expect { @session.assert_current_path('/with_js') }.not_to raise_error
9
10
  end
10
11
 
11
12
  it "should allow regexp matches" do
@@ -18,27 +19,27 @@ Capybara::SpecHelper.spec '#assert_current_path' do
18
19
  end
19
20
 
20
21
  it "should raise if the page has not the given current_path" do
21
- expect{@session.assert_current_path('/with_html')}.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
22
+ expect { @session.assert_current_path('/with_html') }.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
22
23
  end
23
24
 
24
25
  it "should check query options" do
25
26
  @session.visit('/with_js?test=test')
26
- expect{@session.assert_current_path('/with_js?test=test')}.not_to raise_error
27
+ expect { @session.assert_current_path('/with_js?test=test') }.not_to raise_error
27
28
  end
28
29
 
29
30
  it "should compare the full url" do
30
- expect{@session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)}.not_to raise_error
31
+ expect { @session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true) }.not_to raise_error
31
32
  end
32
33
 
33
34
  it "should ignore the query" do
34
35
  @session.visit('/with_js?test=test')
35
- expect{@session.assert_current_path('/with_js', only_path: true)}.not_to raise_error
36
+ expect { @session.assert_current_path('/with_js', ignore_query: true) }.not_to raise_error
36
37
  end
37
38
 
38
39
  it "should not cause an exception when current_url is nil" do
39
40
  allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
40
41
 
41
- expect{@session.assert_current_path(nil)}.not_to raise_error
42
+ expect { @session.assert_current_path(nil) }.not_to raise_error
42
43
  end
43
44
  end
44
45
 
@@ -48,25 +49,25 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
48
49
  end
49
50
 
50
51
  it "should raise if the page has the given current_path" do
51
- expect{@session.assert_no_current_path('/with_js')}.to raise_error(Capybara::ExpectationNotMet)
52
+ expect { @session.assert_no_current_path('/with_js') }.to raise_error(Capybara::ExpectationNotMet)
52
53
  end
53
54
 
54
55
  it "should allow regexp matches" do
55
- expect{@session.assert_no_current_path(/monkey/)}.not_to raise_error
56
+ expect { @session.assert_no_current_path(/monkey/) }.not_to raise_error
56
57
  end
57
58
 
58
59
  it "should wait for current_path to disappear", requires: [:js] do
59
60
  @session.click_link("Change page")
60
- expect{@session.assert_no_current_path('/with_js')}.not_to raise_error
61
+ expect { @session.assert_no_current_path('/with_js') }.not_to raise_error
61
62
  end
62
63
 
63
64
  it "should not raise if the page has not the given current_path" do
64
- expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
65
+ expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
65
66
  end
66
67
 
67
68
  it "should not cause an exception when current_url is nil" do
68
69
  allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
69
70
 
70
- expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
71
+ expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
71
72
  end
72
73
  end