capybara 2.5.0 → 2.18.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 (205) hide show
  1. checksums.yaml +5 -5
  2. data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
  3. data/.yard/templates_custom/default/class/html/setup.rb +17 -0
  4. data/.yard/yard_extensions.rb +78 -0
  5. data/.yardopts +1 -0
  6. data/History.md +413 -10
  7. data/License.txt +1 -1
  8. data/README.md +237 -130
  9. data/lib/capybara/config.rb +132 -0
  10. data/lib/capybara/cucumber.rb +3 -1
  11. data/lib/capybara/driver/base.rb +27 -6
  12. data/lib/capybara/driver/node.rb +14 -5
  13. data/lib/capybara/dsl.rb +2 -3
  14. data/lib/capybara/helpers.rb +13 -65
  15. data/lib/capybara/minitest/spec.rb +177 -0
  16. data/lib/capybara/minitest.rb +278 -0
  17. data/lib/capybara/node/actions.rb +180 -24
  18. data/lib/capybara/node/base.rb +17 -5
  19. data/lib/capybara/node/document.rb +5 -0
  20. data/lib/capybara/node/document_matchers.rb +15 -14
  21. data/lib/capybara/node/element.rb +55 -7
  22. data/lib/capybara/node/finders.rb +179 -67
  23. data/lib/capybara/node/matchers.rb +301 -105
  24. data/lib/capybara/node/simple.rb +15 -4
  25. data/lib/capybara/queries/ancestor_query.rb +25 -0
  26. data/lib/capybara/queries/base_query.rb +69 -3
  27. data/lib/capybara/queries/current_path_query.rb +17 -8
  28. data/lib/capybara/queries/match_query.rb +19 -0
  29. data/lib/capybara/queries/selector_query.rb +251 -0
  30. data/lib/capybara/queries/sibling_query.rb +25 -0
  31. data/lib/capybara/queries/text_query.rb +67 -16
  32. data/lib/capybara/queries/title_query.rb +4 -2
  33. data/lib/capybara/query.rb +3 -131
  34. data/lib/capybara/rack_test/browser.rb +14 -5
  35. data/lib/capybara/rack_test/css_handlers.rb +1 -0
  36. data/lib/capybara/rack_test/driver.rb +15 -8
  37. data/lib/capybara/rack_test/form.rb +34 -12
  38. data/lib/capybara/rack_test/node.rb +29 -12
  39. data/lib/capybara/rails.rb +3 -3
  40. data/lib/capybara/result.rb +104 -9
  41. data/lib/capybara/rspec/compound.rb +95 -0
  42. data/lib/capybara/rspec/features.rb +17 -6
  43. data/lib/capybara/rspec/matcher_proxies.rb +45 -0
  44. data/lib/capybara/rspec/matchers.rb +199 -80
  45. data/lib/capybara/rspec.rb +4 -2
  46. data/lib/capybara/selector/css.rb +30 -0
  47. data/lib/capybara/selector/filter.rb +20 -0
  48. data/lib/capybara/selector/filter_set.rb +74 -0
  49. data/lib/capybara/selector/filters/base.rb +33 -0
  50. data/lib/capybara/selector/filters/expression_filter.rb +40 -0
  51. data/lib/capybara/selector/filters/node_filter.rb +27 -0
  52. data/lib/capybara/selector/selector.rb +276 -0
  53. data/lib/capybara/selector.rb +452 -157
  54. data/lib/capybara/selenium/driver.rb +282 -81
  55. data/lib/capybara/selenium/node.rb +144 -46
  56. data/lib/capybara/server.rb +59 -16
  57. data/lib/capybara/session/config.rb +114 -0
  58. data/lib/capybara/session/matchers.rb +29 -19
  59. data/lib/capybara/session.rb +378 -143
  60. data/lib/capybara/spec/fixtures/no_extension +1 -0
  61. data/lib/capybara/spec/public/jquery-ui.js +13 -791
  62. data/lib/capybara/spec/public/jquery.js +4 -9045
  63. data/lib/capybara/spec/public/test.js +45 -11
  64. data/lib/capybara/spec/session/accept_alert_spec.rb +30 -7
  65. data/lib/capybara/spec/session/accept_confirm_spec.rb +14 -2
  66. data/lib/capybara/spec/session/accept_prompt_spec.rb +35 -6
  67. data/lib/capybara/spec/session/all_spec.rb +45 -32
  68. data/lib/capybara/spec/session/ancestor_spec.rb +85 -0
  69. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +110 -0
  70. data/lib/capybara/spec/session/assert_current_path.rb +15 -2
  71. data/lib/capybara/spec/session/assert_selector.rb +29 -28
  72. data/lib/capybara/spec/session/assert_text.rb +59 -20
  73. data/lib/capybara/spec/session/assert_title.rb +25 -11
  74. data/lib/capybara/spec/session/attach_file_spec.rb +42 -4
  75. data/lib/capybara/spec/session/body_spec.rb +1 -0
  76. data/lib/capybara/spec/session/check_spec.rb +90 -14
  77. data/lib/capybara/spec/session/choose_spec.rb +31 -5
  78. data/lib/capybara/spec/session/click_button_spec.rb +20 -9
  79. data/lib/capybara/spec/session/click_link_or_button_spec.rb +15 -9
  80. data/lib/capybara/spec/session/click_link_spec.rb +39 -15
  81. data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
  82. data/lib/capybara/spec/session/current_url_spec.rb +12 -3
  83. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +6 -5
  84. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +4 -3
  85. data/lib/capybara/spec/session/element/assert_match_selector.rb +36 -0
  86. data/lib/capybara/spec/session/element/match_css_spec.rb +23 -0
  87. data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
  88. data/lib/capybara/spec/session/element/matches_selector_spec.rb +106 -0
  89. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +22 -0
  90. data/lib/capybara/spec/session/evaluate_script_spec.rb +23 -1
  91. data/lib/capybara/spec/session/execute_script_spec.rb +22 -3
  92. data/lib/capybara/spec/session/fill_in_spec.rb +50 -32
  93. data/lib/capybara/spec/session/find_button_spec.rb +43 -2
  94. data/lib/capybara/spec/session/find_by_id_spec.rb +3 -2
  95. data/lib/capybara/spec/session/find_field_spec.rb +42 -6
  96. data/lib/capybara/spec/session/find_link_spec.rb +22 -3
  97. data/lib/capybara/spec/session/find_spec.rb +103 -57
  98. data/lib/capybara/spec/session/first_spec.rb +34 -18
  99. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +103 -0
  100. data/lib/capybara/spec/session/{within_frame_spec.rb → frame/within_frame_spec.rb} +44 -2
  101. data/lib/capybara/spec/session/go_back_spec.rb +2 -1
  102. data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
  103. data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  104. data/lib/capybara/spec/session/has_button_spec.rb +17 -8
  105. data/lib/capybara/spec/session/has_css_spec.rb +85 -73
  106. data/lib/capybara/spec/session/has_current_path_spec.rb +91 -7
  107. data/lib/capybara/spec/session/has_field_spec.rb +93 -58
  108. data/lib/capybara/spec/session/has_link_spec.rb +9 -8
  109. data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
  110. data/lib/capybara/spec/session/has_select_spec.rb +159 -59
  111. data/lib/capybara/spec/session/has_selector_spec.rb +64 -28
  112. data/lib/capybara/spec/session/has_table_spec.rb +1 -0
  113. data/lib/capybara/spec/session/has_text_spec.rb +27 -12
  114. data/lib/capybara/spec/session/has_title_spec.rb +22 -4
  115. data/lib/capybara/spec/session/has_xpath_spec.rb +32 -29
  116. data/lib/capybara/spec/session/headers.rb +2 -1
  117. data/lib/capybara/spec/session/html_spec.rb +4 -3
  118. data/lib/capybara/spec/session/node_spec.rb +198 -38
  119. data/lib/capybara/spec/session/refresh_spec.rb +28 -0
  120. data/lib/capybara/spec/session/reset_session_spec.rb +46 -5
  121. data/lib/capybara/spec/session/response_code.rb +2 -1
  122. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  123. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -5
  124. data/lib/capybara/spec/session/save_page_spec.rb +34 -2
  125. data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
  126. data/lib/capybara/spec/session/screenshot_spec.rb +4 -2
  127. data/lib/capybara/spec/session/select_spec.rb +34 -32
  128. data/lib/capybara/spec/session/selectors_spec.rb +65 -0
  129. data/lib/capybara/spec/session/sibling_spec.rb +52 -0
  130. data/lib/capybara/spec/session/text_spec.rb +4 -4
  131. data/lib/capybara/spec/session/title_spec.rb +2 -1
  132. data/lib/capybara/spec/session/uncheck_spec.rb +42 -2
  133. data/lib/capybara/spec/session/unselect_spec.rb +17 -16
  134. data/lib/capybara/spec/session/visit_spec.rb +77 -2
  135. data/lib/capybara/spec/session/window/become_closed_spec.rb +12 -11
  136. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  137. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  138. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -11
  139. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +7 -4
  140. data/lib/capybara/spec/session/window/window_spec.rb +36 -29
  141. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  142. data/lib/capybara/spec/session/window/within_window_spec.rb +31 -7
  143. data/lib/capybara/spec/session/within_spec.rb +14 -6
  144. data/lib/capybara/spec/spec_helper.rb +37 -4
  145. data/lib/capybara/spec/test_app.rb +15 -3
  146. data/lib/capybara/spec/views/buttons.erb +1 -0
  147. data/lib/capybara/spec/views/fieldsets.erb +2 -1
  148. data/lib/capybara/spec/views/form.erb +169 -9
  149. data/lib/capybara/spec/views/frame_child.erb +10 -2
  150. data/lib/capybara/spec/views/frame_one.erb +2 -1
  151. data/lib/capybara/spec/views/frame_parent.erb +3 -2
  152. data/lib/capybara/spec/views/frame_two.erb +2 -1
  153. data/lib/capybara/spec/views/header_links.erb +1 -0
  154. data/lib/capybara/spec/views/host_links.erb +1 -0
  155. data/lib/capybara/spec/views/initial_alert.erb +10 -0
  156. data/lib/capybara/spec/views/path.erb +1 -0
  157. data/lib/capybara/spec/views/popup_one.erb +1 -0
  158. data/lib/capybara/spec/views/popup_two.erb +1 -0
  159. data/lib/capybara/spec/views/postback.erb +2 -1
  160. data/lib/capybara/spec/views/tables.erb +1 -0
  161. data/lib/capybara/spec/views/with_base_tag.erb +1 -0
  162. data/lib/capybara/spec/views/with_count.erb +2 -1
  163. data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
  164. data/lib/capybara/spec/views/with_hover.erb +7 -1
  165. data/lib/capybara/spec/views/with_html.erb +40 -2
  166. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  167. data/lib/capybara/spec/views/with_js.erb +32 -1
  168. data/lib/capybara/spec/views/with_scope.erb +1 -0
  169. data/lib/capybara/spec/views/with_simple_html.erb +2 -1
  170. data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
  171. data/lib/capybara/spec/views/with_title.erb +2 -1
  172. data/lib/capybara/spec/views/with_unload_alert.erb +14 -0
  173. data/lib/capybara/spec/views/with_windows.erb +7 -0
  174. data/lib/capybara/spec/views/within_frames.erb +3 -2
  175. data/lib/capybara/version.rb +2 -1
  176. data/lib/capybara/window.rb +20 -3
  177. data/lib/capybara.rb +189 -93
  178. data/spec/basic_node_spec.rb +7 -6
  179. data/spec/capybara_spec.rb +90 -4
  180. data/spec/dsl_spec.rb +3 -1
  181. data/spec/filter_set_spec.rb +28 -0
  182. data/spec/fixtures/capybara.csv +1 -0
  183. data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -1
  184. data/spec/fixtures/selenium_driver_rspec_success.rb +5 -1
  185. data/spec/minitest_spec.rb +130 -0
  186. data/spec/minitest_spec_spec.rb +135 -0
  187. data/spec/per_session_config_spec.rb +67 -0
  188. data/spec/rack_test_spec.rb +50 -7
  189. data/spec/result_spec.rb +76 -0
  190. data/spec/rspec/features_spec.rb +21 -8
  191. data/spec/rspec/scenarios_spec.rb +21 -0
  192. data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +160 -54
  193. data/spec/rspec/views_spec.rb +5 -0
  194. data/spec/rspec_matchers_spec.rb +46 -0
  195. data/spec/rspec_spec.rb +79 -1
  196. data/spec/selector_spec.rb +199 -0
  197. data/spec/selenium_spec_chrome.rb +54 -9
  198. data/spec/selenium_spec_firefox.rb +68 -0
  199. data/spec/selenium_spec_marionette.rb +127 -0
  200. data/spec/server_spec.rb +102 -14
  201. data/spec/session_spec.rb +54 -0
  202. data/spec/shared_selenium_session.rb +215 -0
  203. data/spec/spec_helper.rb +7 -0
  204. metadata +140 -15
  205. data/spec/selenium_spec.rb +0 -128
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_field' do
2
3
  before { @session.visit('/form') }
3
4
 
@@ -14,44 +15,60 @@ Capybara::SpecHelper.spec '#has_field' do
14
15
 
15
16
  context 'with value' do
16
17
  it "should be true if a field with the given value is on the page" do
17
- expect(@session).to have_field('First Name', :with => 'John')
18
- expect(@session).to have_field('Phone', :with => '+1 555 7021')
19
- expect(@session).to have_field('Street', :with => 'Sesame street 66')
20
- expect(@session).to have_field('Description', :with => 'Descriptive text goes here')
18
+ expect(@session).to have_field('First Name', with: 'John')
19
+ expect(@session).to have_field('First Name', with: /^Joh/)
20
+ expect(@session).to have_field('Phone', with: '+1 555 7021')
21
+ expect(@session).to have_field('Street', with: 'Sesame street 66')
22
+ expect(@session).to have_field('Description', with: 'Descriptive text goes here')
21
23
  end
22
24
 
23
25
  it "should be false if the given field is not on the page" do
24
- expect(@session).not_to have_field('First Name', :with => 'Peter')
25
- expect(@session).not_to have_field('Wrong Name', :with => 'John')
26
- expect(@session).not_to have_field('Description', :with => 'Monkey')
26
+ expect(@session).not_to have_field('First Name', with: 'Peter')
27
+ expect(@session).not_to have_field('First Name', with: /eter$/)
28
+ expect(@session).not_to have_field('Wrong Name', with: 'John')
29
+ expect(@session).not_to have_field('Description', with: 'Monkey')
27
30
  end
28
31
 
29
32
  it "should be true after the field has been filled in with the given value" do
30
- @session.fill_in('First Name', :with => 'Jonas')
31
- expect(@session).to have_field('First Name', :with => 'Jonas')
33
+ @session.fill_in('First Name', with: 'Jonas')
34
+ expect(@session).to have_field('First Name', with: 'Jonas')
35
+ expect(@session).to have_field('First Name', with: /ona/)
32
36
  end
33
37
 
34
38
  it "should be false after the field has been filled in with a different value" do
35
- @session.fill_in('First Name', :with => 'Jonas')
36
- expect(@session).not_to have_field('First Name', :with => 'John')
39
+ @session.fill_in('First Name', with: 'Jonas')
40
+ expect(@session).not_to have_field('First Name', with: 'John')
41
+ expect(@session).not_to have_field('First Name', with: /John|Paul|George|Ringo/)
37
42
  end
38
43
  end
39
44
 
40
45
  context 'with type' do
41
46
  it "should be true if a field with the given type is on the page" do
42
- expect(@session).to have_field('First Name', :type => 'text')
43
- expect(@session).to have_field('Html5 Email', :type => 'email')
44
- expect(@session).to have_field('Html5 Tel', :type => 'tel')
45
- expect(@session).to have_field('Description', :type => 'textarea')
46
- expect(@session).to have_field('Languages', :type => 'select')
47
+ expect(@session).to have_field('First Name', type: 'text')
48
+ expect(@session).to have_field('Html5 Email', type: 'email')
49
+ expect(@session).to have_field('Html5 Multiple Email', type: 'email')
50
+ expect(@session).to have_field('Html5 Tel', type: 'tel')
51
+ expect(@session).to have_field('Description', type: 'textarea')
52
+ expect(@session).to have_field('Languages', type: 'select')
47
53
  end
48
54
 
49
55
  it "should be false if the given field is not on the page" do
50
- expect(@session).not_to have_field('First Name', :type => 'textarea')
51
- expect(@session).not_to have_field('Html5 Email', :type => 'tel')
52
- expect(@session).not_to have_field('Description', :type => '')
53
- expect(@session).not_to have_field('Description', :type => 'email')
54
- expect(@session).not_to have_field('Languages', :type => 'textarea')
56
+ expect(@session).not_to have_field('First Name', type: 'textarea')
57
+ expect(@session).not_to have_field('Html5 Email', type: 'tel')
58
+ expect(@session).not_to have_field('Html5 Multiple Email', type: 'tel')
59
+ expect(@session).not_to have_field('Description', type: '')
60
+ expect(@session).not_to have_field('Description', type: 'email')
61
+ expect(@session).not_to have_field('Languages', type: 'textarea')
62
+ end
63
+ end
64
+
65
+ context 'with multiple' do
66
+ it "should be true if a field with the multiple attribute is on the page" do
67
+ expect(@session).to have_field('Html5 Multiple Email', multiple: true)
68
+ end
69
+
70
+ it "should be false if a field without the multiple attribute is not on the page" do
71
+ expect(@session).not_to have_field('Html5 Multiple Email', multiple: false)
55
72
  end
56
73
  end
57
74
  end
@@ -71,44 +88,44 @@ Capybara::SpecHelper.spec '#has_no_field' do
71
88
 
72
89
  context 'with value' do
73
90
  it "should be false if a field with the given value is on the page" do
74
- expect(@session).not_to have_no_field('First Name', :with => 'John')
75
- expect(@session).not_to have_no_field('Phone', :with => '+1 555 7021')
76
- expect(@session).not_to have_no_field('Street', :with => 'Sesame street 66')
77
- expect(@session).not_to have_no_field('Description', :with => 'Descriptive text goes here')
91
+ expect(@session).not_to have_no_field('First Name', with: 'John')
92
+ expect(@session).not_to have_no_field('Phone', with: '+1 555 7021')
93
+ expect(@session).not_to have_no_field('Street', with: 'Sesame street 66')
94
+ expect(@session).not_to have_no_field('Description', with: 'Descriptive text goes here')
78
95
  end
79
96
 
80
97
  it "should be true if the given field is not on the page" do
81
- expect(@session).to have_no_field('First Name', :with => 'Peter')
82
- expect(@session).to have_no_field('Wrong Name', :with => 'John')
83
- expect(@session).to have_no_field('Description', :with => 'Monkey')
98
+ expect(@session).to have_no_field('First Name', with: 'Peter')
99
+ expect(@session).to have_no_field('Wrong Name', with: 'John')
100
+ expect(@session).to have_no_field('Description', with: 'Monkey')
84
101
  end
85
102
 
86
103
  it "should be false after the field has been filled in with the given value" do
87
- @session.fill_in('First Name', :with => 'Jonas')
88
- expect(@session).not_to have_no_field('First Name', :with => 'Jonas')
104
+ @session.fill_in('First Name', with: 'Jonas')
105
+ expect(@session).not_to have_no_field('First Name', with: 'Jonas')
89
106
  end
90
107
 
91
108
  it "should be true after the field has been filled in with a different value" do
92
- @session.fill_in('First Name', :with => 'Jonas')
93
- expect(@session).to have_no_field('First Name', :with => 'John')
109
+ @session.fill_in('First Name', with: 'Jonas')
110
+ expect(@session).to have_no_field('First Name', with: 'John')
94
111
  end
95
112
  end
96
113
 
97
114
  context 'with type' do
98
115
  it "should be false if a field with the given type is on the page" do
99
- expect(@session).not_to have_no_field('First Name', :type => 'text')
100
- expect(@session).not_to have_no_field('Html5 Email', :type => 'email')
101
- expect(@session).not_to have_no_field('Html5 Tel', :type => 'tel')
102
- expect(@session).not_to have_no_field('Description', :type => 'textarea')
103
- expect(@session).not_to have_no_field('Languages', :type => 'select')
116
+ expect(@session).not_to have_no_field('First Name', type: 'text')
117
+ expect(@session).not_to have_no_field('Html5 Email', type: 'email')
118
+ expect(@session).not_to have_no_field('Html5 Tel', type: 'tel')
119
+ expect(@session).not_to have_no_field('Description', type: 'textarea')
120
+ expect(@session).not_to have_no_field('Languages', type: 'select')
104
121
  end
105
122
 
106
123
  it "should be true if the given field is not on the page" do
107
- expect(@session).to have_no_field('First Name', :type => 'textarea')
108
- expect(@session).to have_no_field('Html5 Email', :type => 'tel')
109
- expect(@session).to have_no_field('Description', :type => '')
110
- expect(@session).to have_no_field('Description', :type => 'email')
111
- expect(@session).to have_no_field('Languages', :type => 'textarea')
124
+ expect(@session).to have_no_field('First Name', type: 'textarea')
125
+ expect(@session).to have_no_field('Html5 Email', type: 'tel')
126
+ expect(@session).to have_no_field('Description', type: '')
127
+ expect(@session).to have_no_field('Description', type: 'email')
128
+ expect(@session).to have_no_field('Languages', type: 'textarea')
112
129
  end
113
130
  end
114
131
  end
@@ -121,8 +138,8 @@ Capybara::SpecHelper.spec '#has_checked_field?' do
121
138
  expect(@session).to have_checked_field('Hamster')
122
139
  end
123
140
 
124
- it "should be true for disabled checkboxes if :disabled => true" do
125
- expect(@session).to have_checked_field('Disabled Checkbox', :disabled => true)
141
+ it "should be true for disabled checkboxes if disabled: true" do
142
+ expect(@session).to have_checked_field('Disabled Checkbox', disabled: true)
126
143
  end
127
144
 
128
145
  it "should be false if an unchecked field is on the page" do
@@ -138,8 +155,16 @@ Capybara::SpecHelper.spec '#has_checked_field?' do
138
155
  expect(@session).not_to have_checked_field('Disabled Checkbox')
139
156
  end
140
157
 
141
- it "should be false for disabled checkboxes if :disabled => false" do
142
- expect(@session).not_to have_checked_field('Disabled Checkbox', :disabled => false)
158
+ it "should be false for disabled checkboxes if disabled: false" do
159
+ expect(@session).not_to have_checked_field('Disabled Checkbox', disabled: false)
160
+ end
161
+
162
+ it "should be true for disabled checkboxes if disabled: :all" do
163
+ expect(@session).to have_checked_field('Disabled Checkbox', disabled: :all)
164
+ end
165
+
166
+ it "should be true for enabled checkboxes if disabled: :all" do
167
+ expect(@session).to have_checked_field('gender_female', disabled: :all)
143
168
  end
144
169
 
145
170
  it "should be true after an unchecked checkbox is checked" do
@@ -171,8 +196,8 @@ Capybara::SpecHelper.spec '#has_no_checked_field?' do
171
196
  expect(@session).not_to have_no_checked_field('Hamster')
172
197
  end
173
198
 
174
- it "should be false for disabled checkboxes if :disabled => true" do
175
- expect(@session).not_to have_no_checked_field('Disabled Checkbox', :disabled => true)
199
+ it "should be false for disabled checkboxes if disabled: true" do
200
+ expect(@session).not_to have_no_checked_field('Disabled Checkbox', disabled: true)
176
201
  end
177
202
 
178
203
  it "should be true if an unchecked field is on the page" do
@@ -188,8 +213,8 @@ Capybara::SpecHelper.spec '#has_no_checked_field?' do
188
213
  expect(@session).to have_no_checked_field('Disabled Checkbox')
189
214
  end
190
215
 
191
- it "should be true for disabled checkboxes if :disabled => false" do
192
- expect(@session).to have_no_checked_field('Disabled Checkbox', :disabled => false)
216
+ it "should be true for disabled checkboxes if disabled: false" do
217
+ expect(@session).to have_no_checked_field('Disabled Checkbox', disabled: false)
193
218
  end
194
219
  end
195
220
 
@@ -206,8 +231,8 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
206
231
  expect(@session).to have_unchecked_field('Male')
207
232
  end
208
233
 
209
- it "should be true for disabled unchecked fields if :disabled => true" do
210
- expect(@session).to have_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
234
+ it "should be true for disabled unchecked fields if disabled: true" do
235
+ expect(@session).to have_unchecked_field('Disabled Unchecked Checkbox', disabled: true)
211
236
  end
212
237
 
213
238
  it "should be false if no field is on the page" do
@@ -218,8 +243,8 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
218
243
  expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox')
219
244
  end
220
245
 
221
- it "should be false for disabled unchecked fields if :disabled => false" do
222
- expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
246
+ it "should be false for disabled unchecked fields if disabled: false" do
247
+ expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox', disabled: false)
223
248
  end
224
249
 
225
250
  it "should be false after an unchecked checkbox is checked" do
@@ -241,6 +266,11 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
241
266
  @session.choose('gender_male')
242
267
  expect(@session).to have_unchecked_field('gender_female')
243
268
  end
269
+
270
+ it "should support locator-less usage" do
271
+ expect(@session.has_unchecked_field?(disabled: true, id: "form_disabled_unchecked_checkbox"))
272
+ expect(@session).to have_unchecked_field(disabled: true, id: "form_disabled_unchecked_checkbox" )
273
+ end
244
274
  end
245
275
 
246
276
  Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
@@ -256,8 +286,8 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
256
286
  expect(@session).not_to have_no_unchecked_field('Male')
257
287
  end
258
288
 
259
- it "should be false for disabled unchecked fields if :disabled => true" do
260
- expect(@session).not_to have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
289
+ it "should be false for disabled unchecked fields if disabled: true" do
290
+ expect(@session).not_to have_no_unchecked_field('Disabled Unchecked Checkbox', disabled: true)
261
291
  end
262
292
 
263
293
  it "should be true if no field is on the page" do
@@ -268,7 +298,12 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
268
298
  expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox')
269
299
  end
270
300
 
271
- it "should be true for disabled unchecked fields if :disabled => false" do
272
- expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
301
+ it "should be true for disabled unchecked fields if disabled: false" do
302
+ expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox', disabled: false)
303
+ end
304
+
305
+ it "should support locator-less usage" do
306
+ expect(@session.has_no_unchecked_field?(disabled: false, id: "form_disabled_unchecked_checkbox")).to eq true
307
+ expect(@session).to have_no_unchecked_field(disabled: false, id: "form_disabled_unchecked_checkbox" )
273
308
  end
274
309
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_link?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -6,15 +7,15 @@ Capybara::SpecHelper.spec '#has_link?' do
6
7
  it "should be true if the given link is on the page" do
7
8
  expect(@session).to have_link('foo')
8
9
  expect(@session).to have_link('awesome title')
9
- expect(@session).to have_link('A link', :href => '/with_simple_html')
10
- expect(@session).to have_link(:'A link', :href => :'/with_simple_html')
11
- expect(@session).to have_link('A link', :href => /\/with_simple_html/)
10
+ expect(@session).to have_link('A link', href: '/with_simple_html')
11
+ expect(@session).to have_link(:'A link', href: :'/with_simple_html')
12
+ expect(@session).to have_link('A link', href: /\/with_simple_html/)
12
13
  end
13
14
 
14
15
  it "should be false if the given link is not on the page" do
15
16
  expect(@session).not_to have_link('monkey')
16
- expect(@session).not_to have_link('A link', :href => '/non-existant-href')
17
- expect(@session).not_to have_link('A link', :href => /non-existant/)
17
+ expect(@session).not_to have_link('A link', href: '/nonexistent-href')
18
+ expect(@session).not_to have_link('A link', href: /nonexistent/)
18
19
  end
19
20
  end
20
21
 
@@ -26,12 +27,12 @@ Capybara::SpecHelper.spec '#has_no_link?' do
26
27
  it "should be false if the given link is on the page" do
27
28
  expect(@session).not_to have_no_link('foo')
28
29
  expect(@session).not_to have_no_link('awesome title')
29
- expect(@session).not_to have_no_link('A link', :href => '/with_simple_html')
30
+ expect(@session).not_to have_no_link('A link', href: '/with_simple_html')
30
31
  end
31
32
 
32
33
  it "should be true if the given link is not on the page" do
33
34
  expect(@session).to have_no_link('monkey')
34
- expect(@session).to have_no_link('A link', :href => '/non-existant-href')
35
- expect(@session).to have_no_link('A link', :href => /\/non-existant-href/)
35
+ expect(@session).to have_no_link('A link', href: '/nonexistent-href')
36
+ expect(@session).to have_no_link('A link', href: /\/nonexistent-href/)
36
37
  end
37
38
  end
@@ -0,0 +1,76 @@
1
+ Capybara::SpecHelper.spec '#have_none_of_selectors' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should be false if any of the given locators are on the page" do
7
+ expect {
8
+ expect(@session).to have_none_of_selectors(:xpath, "//p", "//a")
9
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
10
+ expect {
11
+ expect(@session).to have_none_of_selectors(:css, "p a#foo")
12
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
13
+ end
14
+
15
+ it "should be true if none of the given locators are on the page" do
16
+ expect(@session).to have_none_of_selectors(:xpath, "//abbr", "//td" )
17
+ expect(@session).to have_none_of_selectors(:css, "p a#doesnotexist", "abbr")
18
+ end
19
+
20
+ it "should use default selector" do
21
+ Capybara.default_selector = :css
22
+ expect(@session).to have_none_of_selectors("p a#doesnotexist", "abbr")
23
+ expect {
24
+ expect(@session).to have_none_of_selectors("abbr", "p a#foo")
25
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
26
+ end
27
+
28
+ context "should respect scopes" do
29
+ it "when used with `within`" do
30
+ @session.within "//p[@id='first']" do
31
+ expect {
32
+ expect(@session).to have_none_of_selectors(".//a[@id='foo']")
33
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
34
+ expect(@session).to have_none_of_selectors(".//a[@id='red']")
35
+ end
36
+ end
37
+
38
+ it "when called on an element" do
39
+ el = @session.find "//p[@id='first']"
40
+ expect {
41
+ expect(el).to have_none_of_selectors(".//a[@id='foo']")
42
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
43
+ expect(el).to have_none_of_selectors(".//a[@id='red']")
44
+ end
45
+ end
46
+
47
+ context "with options" do
48
+ it "should apply the options to all locators" do
49
+ expect {
50
+ expect(@session).to have_none_of_selectors("//p//a", text: "Redirect")
51
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
52
+ expect(@session).to have_none_of_selectors("//p", text: "Doesnotexist")
53
+ end
54
+
55
+ it "should discard all matches where the given regexp is matched" do
56
+ expect {
57
+ expect(@session).to have_none_of_selectors("//p//a", text: /re[dab]i/i, count: 1)
58
+ }.to raise_error ::RSpec::Expectations::ExpectationNotMetError
59
+ expect(@session).to have_none_of_selectors("//p//a", text: /Red$/)
60
+ end
61
+ end
62
+
63
+ context "with wait", requires: [:js] do
64
+ it "should not find elements if they appear after given wait duration" do
65
+ @session.visit('/with_js')
66
+ @session.click_link('Click me')
67
+ expect(@session).to have_none_of_selectors(:css, "#new_field", "a#has-been-clicked", wait: 0.1)
68
+ end
69
+ end
70
+
71
+ it "cannot be negated" do
72
+ expect {
73
+ expect(@session).not_to have_none_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
74
+ }.to raise_error ArgumentError
75
+ end
76
+ end