capybara 2.5.0 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
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_select?' do
2
3
  before { @session.visit('/form') }
3
4
 
@@ -14,80 +15,147 @@ Capybara::SpecHelper.spec '#has_select?' do
14
15
 
15
16
  context 'with selected 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_select('form_locale', :selected => 'English')
18
- expect(@session).to have_select('Region', :selected => 'Norway')
19
- expect(@session).to have_select('Underwear', :selected => [
18
+ expect(@session).to have_select('form_locale', selected: 'English')
19
+ expect(@session).to have_select('Region', selected: 'Norway')
20
+ expect(@session).to have_select('Underwear', selected: [
20
21
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
21
22
  ])
22
23
  end
23
24
 
24
25
  it "should be false if the given field is not on the page" do
25
- expect(@session).not_to have_select('Locale', :selected => 'Swedish')
26
- expect(@session).not_to have_select('Does not exist', :selected => 'John')
27
- expect(@session).not_to have_select('City', :selected => 'Not there')
28
- expect(@session).not_to have_select('Underwear', :selected => [
29
- 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
26
+ expect(@session).not_to have_select('Locale', selected: 'Swedish')
27
+ expect(@session).not_to have_select('Does not exist', selected: 'John')
28
+ expect(@session).not_to have_select('City', selected: 'Not there')
29
+ expect(@session).not_to have_select('Underwear', selected: [
30
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistent'
30
31
  ])
31
- expect(@session).not_to have_select('Underwear', :selected => [
32
+ expect(@session).not_to have_select('Underwear', selected: [
32
33
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
33
34
  ])
34
- expect(@session).not_to have_select('Underwear', :selected => [
35
+ expect(@session).not_to have_select('Underwear', selected: [
35
36
  'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
36
37
  ])
37
38
  end
38
39
 
39
40
  it "should be true after the given value is selected" do
40
- @session.select('Swedish', :from => 'Locale')
41
- expect(@session).to have_select('Locale', :selected => 'Swedish')
41
+ @session.select('Swedish', from: 'Locale')
42
+ expect(@session).to have_select('Locale', selected: 'Swedish')
42
43
  end
43
44
 
44
45
  it "should be false after a different value is selected" do
45
- @session.select('Swedish', :from => 'Locale')
46
- expect(@session).not_to have_select('Locale', :selected => 'English')
46
+ @session.select('Swedish', from: 'Locale')
47
+ expect(@session).not_to have_select('Locale', selected: 'English')
47
48
  end
48
49
 
49
50
  it "should be true after the given values are selected" do
50
- @session.select('Boxers', :from => 'Underwear')
51
- expect(@session).to have_select('Underwear', :selected => [
51
+ @session.select('Boxers', from: 'Underwear')
52
+ expect(@session).to have_select('Underwear', selected: [
52
53
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
53
54
  ])
54
55
  end
55
56
 
56
57
  it "should be false after one of the values is unselected" do
57
- @session.unselect('Briefs', :from => 'Underwear')
58
- expect(@session).not_to have_select('Underwear', :selected => [
58
+ @session.unselect('Briefs', from: 'Underwear')
59
+ expect(@session).not_to have_select('Underwear', selected: [
59
60
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
60
61
  ])
61
62
  end
63
+
64
+ it "should be true even when the selected option invisible, regardless of the select's visibility" do
65
+ expect(@session).to have_select('Icecream', visible: false, selected: 'Chocolate')
66
+ expect(@session).to have_select('Sorbet', selected: 'Vanilla')
67
+ end
68
+ end
69
+
70
+ context 'with partial select' do
71
+ it "should be true if a field with the given partial values is on the page" do
72
+ expect(@session).to have_select('Underwear', with_selected: ['Boxerbriefs', 'Briefs'])
73
+ end
74
+
75
+ it "should be false if a field with the given partial values is not on the page" do
76
+ expect(@session).not_to have_select('Underwear', with_selected: ['Boxerbriefs', 'Boxers'])
77
+ end
78
+
79
+ it "should be true after the given partial value is selected" do
80
+ @session.select('Boxers', from: 'Underwear')
81
+ expect(@session).to have_select('Underwear', with_selected: ['Boxerbriefs', 'Boxers'])
82
+ end
83
+
84
+ it "should be false after one of the given partial values is unselected" do
85
+ @session.unselect('Briefs', from: 'Underwear')
86
+ expect(@session).not_to have_select('Underwear', with_selected: ['Boxerbriefs', 'Briefs'])
87
+ end
88
+
89
+ it "should be true even when the selected values are invisible, regardless of the select's visibility" do
90
+ expect(@session).to have_select('Dessert', visible: false, with_options: ['Pudding', 'Tiramisu'])
91
+ expect(@session).to have_select('Cake', with_selected: ['Chocolate Cake', 'Sponge Cake'])
92
+ end
93
+
94
+ it "should support non array partial values" do
95
+ expect(@session).to have_select('Underwear', with_selected: 'Briefs')
96
+ expect(@session).not_to have_select('Underwear', with_selected: 'Boxers')
97
+ end
62
98
  end
63
99
 
64
100
  context 'with exact options' do
65
101
  it "should be true if a field with the given options is on the page" do
66
- expect(@session).to have_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
67
- expect(@session).to have_select('Tendency', :options => [])
102
+ expect(@session).to have_select('Region', options: ['Norway', 'Sweden', 'Finland'])
103
+ expect(@session).to have_select('Tendency', options: [])
68
104
  end
69
105
 
70
106
  it "should be false if the given field is not on the page" do
71
- expect(@session).not_to have_select('Locale', :options => ['Swedish'])
72
- expect(@session).not_to have_select('Does not exist', :options => ['John'])
73
- expect(@session).not_to have_select('City', :options => ['London', 'Made up city'])
74
- expect(@session).not_to have_select('Region', :options => ['Norway', 'Sweden'])
75
- expect(@session).not_to have_select('Region', :options => ['Norway', 'Norway', 'Norway'])
107
+ expect(@session).not_to have_select('Locale', options: ['Swedish'])
108
+ expect(@session).not_to have_select('Does not exist', options: ['John'])
109
+ expect(@session).not_to have_select('City', options: ['London', 'Made up city'])
110
+ expect(@session).not_to have_select('Region', options: ['Norway', 'Sweden'])
111
+ expect(@session).not_to have_select('Region', options: ['Norway', 'Norway', 'Norway'])
112
+ end
113
+
114
+ it "should be true even when the options are invisible, if the select itself is invisible" do
115
+ expect(@session).to have_select("Icecream", visible: false, options: ['Chocolate', 'Vanilla', 'Strawberry'])
76
116
  end
77
117
  end
78
118
 
79
119
  context 'with partial options' do
80
120
  it "should be true if a field with the given partial options is on the page" do
81
- expect(@session).to have_select('Region', :with_options => ['Norway', 'Sweden'])
82
- expect(@session).to have_select('City', :with_options => ['London'])
121
+ expect(@session).to have_select('Region', with_options: ['Norway', 'Sweden'])
122
+ expect(@session).to have_select('City', with_options: ['London'])
83
123
  end
84
124
 
85
125
  it "should be false if a field with the given partial options is not on the page" do
86
- expect(@session).not_to have_select('Locale', :with_options => ['Uruguayan'])
87
- expect(@session).not_to have_select('Does not exist', :with_options => ['John'])
88
- expect(@session).not_to have_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
126
+ expect(@session).not_to have_select('Locale', with_options: ['Uruguayan'])
127
+ expect(@session).not_to have_select('Does not exist', with_options: ['John'])
128
+ expect(@session).not_to have_select('Region', with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])
129
+ end
130
+
131
+ it "should be true even when the options are invisible, if the select itself is invisible" do
132
+ expect(@session).to have_select("Icecream", visible: false, with_options: ['Vanilla', 'Strawberry'])
89
133
  end
90
134
  end
135
+
136
+ context 'with multiple option' do
137
+ it "should find multiple selects if true" do
138
+ expect(@session).to have_select('form_languages', multiple: true)
139
+ expect(@session).not_to have_select('form_other_title', multiple: true)
140
+ end
141
+
142
+ it "should not find multiple selects if false" do
143
+ expect(@session).not_to have_select('form_languages', multiple: false)
144
+ expect(@session).to have_select('form_other_title', multiple: false)
145
+ end
146
+
147
+ it "should find both if not specified" do
148
+ expect(@session).to have_select('form_languages')
149
+ expect(@session).to have_select('form_other_title')
150
+ end
151
+ end
152
+
153
+ it "should support locator-less usage" do
154
+ expect(@session.has_select?(with_options: ['Norway', 'Sweden'])).to eq true
155
+ expect(@session).to have_select(with_options: ['London'])
156
+ expect(@session.has_select?(with_selected: ['Commando', 'Boxerbriefs'])).to eq true
157
+ expect(@session).to have_select(with_selected: ['Briefs'])
158
+ end
91
159
  end
92
160
 
93
161
  Capybara::SpecHelper.spec '#has_no_select?' do
@@ -105,77 +173,109 @@ Capybara::SpecHelper.spec '#has_no_select?' do
105
173
 
106
174
  context 'with selected value' do
107
175
  it "should be false if a field with the given value is on the page" do
108
- expect(@session).not_to have_no_select('form_locale', :selected => 'English')
109
- expect(@session).not_to have_no_select('Region', :selected => 'Norway')
110
- expect(@session).not_to have_no_select('Underwear', :selected => [
176
+ expect(@session).not_to have_no_select('form_locale', selected: 'English')
177
+ expect(@session).not_to have_no_select('Region', selected: 'Norway')
178
+ expect(@session).not_to have_no_select('Underwear', selected: [
111
179
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
112
180
  ])
113
181
  end
114
182
 
115
183
  it "should be true if the given field is not on the page" do
116
- expect(@session).to have_no_select('Locale', :selected => 'Swedish')
117
- expect(@session).to have_no_select('Does not exist', :selected => 'John')
118
- expect(@session).to have_no_select('City', :selected => 'Not there')
119
- expect(@session).to have_no_select('Underwear', :selected => [
120
- 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
184
+ expect(@session).to have_no_select('Locale', selected: 'Swedish')
185
+ expect(@session).to have_no_select('Does not exist', selected: 'John')
186
+ expect(@session).to have_no_select('City', selected: 'Not there')
187
+ expect(@session).to have_no_select('Underwear', selected: [
188
+ 'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistent'
121
189
  ])
122
- expect(@session).to have_no_select('Underwear', :selected => [
190
+ expect(@session).to have_no_select('Underwear', selected: [
123
191
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
124
192
  ])
125
- expect(@session).to have_no_select('Underwear', :selected => [
193
+ expect(@session).to have_no_select('Underwear', selected: [
126
194
  'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
127
195
  ])
128
196
  end
129
197
 
130
198
  it "should be false after the given value is selected" do
131
- @session.select('Swedish', :from => 'Locale')
132
- expect(@session).not_to have_no_select('Locale', :selected => 'Swedish')
199
+ @session.select('Swedish', from: 'Locale')
200
+ expect(@session).not_to have_no_select('Locale', selected: 'Swedish')
133
201
  end
134
202
 
135
203
  it "should be true after a different value is selected" do
136
- @session.select('Swedish', :from => 'Locale')
137
- expect(@session).to have_no_select('Locale', :selected => 'English')
204
+ @session.select('Swedish', from: 'Locale')
205
+ expect(@session).to have_no_select('Locale', selected: 'English')
138
206
  end
139
207
 
140
208
  it "should be false after the given values are selected" do
141
- @session.select('Boxers', :from => 'Underwear')
142
- expect(@session).not_to have_no_select('Underwear', :selected => [
209
+ @session.select('Boxers', from: 'Underwear')
210
+ expect(@session).not_to have_no_select('Underwear', selected: [
143
211
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
144
212
  ])
145
213
  end
146
214
 
147
215
  it "should be true after one of the values is unselected" do
148
- @session.unselect('Briefs', :from => 'Underwear')
149
- expect(@session).to have_no_select('Underwear', :selected => [
216
+ @session.unselect('Briefs', from: 'Underwear')
217
+ expect(@session).to have_no_select('Underwear', selected: [
150
218
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
151
219
  ])
152
220
  end
153
221
  end
154
222
 
223
+ context 'with partial select' do
224
+ it "should be false if a field with the given partial values is on the page" do
225
+ expect(@session).not_to have_no_select('Underwear', with_selected: ['Boxerbriefs', 'Briefs'])
226
+ end
227
+
228
+ it "should be true if a field with the given partial values is not on the page" do
229
+ expect(@session).to have_no_select('Underwear', with_selected: ['Boxerbriefs', 'Boxers'])
230
+ end
231
+
232
+ it "should be false after the given partial value is selected" do
233
+ @session.select('Boxers', from: 'Underwear')
234
+ expect(@session).not_to have_no_select('Underwear', with_selected: ['Boxerbriefs', 'Boxers'])
235
+ end
236
+
237
+ it "should be true after one of the given partial values is unselected" do
238
+ @session.unselect('Briefs', from: 'Underwear')
239
+ expect(@session).to have_no_select('Underwear', with_selected: ['Boxerbriefs', 'Briefs'])
240
+ end
241
+
242
+ it "should support non array partial values" do
243
+ expect(@session).not_to have_no_select('Underwear', with_selected: 'Briefs')
244
+ expect(@session).to have_no_select('Underwear', with_selected: 'Boxers')
245
+ end
246
+ end
247
+
155
248
  context 'with exact options' do
156
249
  it "should be false if a field with the given options is on the page" do
157
- expect(@session).not_to have_no_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
250
+ expect(@session).not_to have_no_select('Region', options: ['Norway', 'Sweden', 'Finland'])
158
251
  end
159
252
 
160
253
  it "should be true if the given field is not on the page" do
161
- expect(@session).to have_no_select('Locale', :options => ['Swedish'])
162
- expect(@session).to have_no_select('Does not exist', :options => ['John'])
163
- expect(@session).to have_no_select('City', :options => ['London', 'Made up city'])
164
- expect(@session).to have_no_select('Region', :options => ['Norway', 'Sweden'])
165
- expect(@session).to have_no_select('Region', :options => ['Norway', 'Norway', 'Norway'])
254
+ expect(@session).to have_no_select('Locale', options: ['Swedish'])
255
+ expect(@session).to have_no_select('Does not exist', options: ['John'])
256
+ expect(@session).to have_no_select('City', options: ['London', 'Made up city'])
257
+ expect(@session).to have_no_select('Region', options: ['Norway', 'Sweden'])
258
+ expect(@session).to have_no_select('Region', options: ['Norway', 'Norway', 'Norway'])
166
259
  end
167
260
  end
168
261
 
169
262
  context 'with partial options' do
170
263
  it "should be false if a field with the given partial options is on the page" do
171
- expect(@session).not_to have_no_select('Region', :with_options => ['Norway', 'Sweden'])
172
- expect(@session).not_to have_no_select('City', :with_options => ['London'])
264
+ expect(@session).not_to have_no_select('Region', with_options: ['Norway', 'Sweden'])
265
+ expect(@session).not_to have_no_select('City', with_options: ['London'])
173
266
  end
174
267
 
175
268
  it "should be true if a field with the given partial options is not on the page" do
176
- expect(@session).to have_no_select('Locale', :with_options => ['Uruguayan'])
177
- expect(@session).to have_no_select('Does not exist', :with_options => ['John'])
178
- expect(@session).to have_no_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
269
+ expect(@session).to have_no_select('Locale', with_options: ['Uruguayan'])
270
+ expect(@session).to have_no_select('Does not exist', with_options: ['John'])
271
+ expect(@session).to have_no_select('Region', with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])
179
272
  end
180
273
  end
274
+
275
+ it "should support locator-less usage" do
276
+ expect(@session.has_no_select?(with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])).to eq true
277
+ expect(@session).to have_no_select(with_options: ['New London'] )
278
+ expect(@session.has_no_select?(with_selected: ['Boxers'])).to eq true
279
+ expect(@session).to have_no_select(with_selected: ['Commando', 'Boxers'])
280
+ end
181
281
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_selector?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -28,43 +29,73 @@ Capybara::SpecHelper.spec '#has_selector?' do
28
29
  end
29
30
  end
30
31
 
32
+ it "should accept a filter block" do
33
+ expect(@session).to have_selector(:css, "a", count: 1) { |el| el[:id] == "foo" }
34
+ end
35
+
31
36
  context "with count" do
32
37
  it "should be true if the content is on the page the given number of times" do
33
- expect(@session).to have_selector("//p", :count => 3)
34
- expect(@session).to have_selector("//p//a[@id='foo']", :count => 1)
35
- expect(@session).to have_selector("//p[contains(.,'est')]", :count => 1)
38
+ expect(@session).to have_selector("//p", count: 3)
39
+ expect(@session).to have_selector("//p//a[@id='foo']", count: 1)
40
+ expect(@session).to have_selector("//p[contains(.,'est')]", count: 1)
36
41
  end
37
42
 
38
43
  it "should be false if the content is on the page the given number of times" do
39
- expect(@session).not_to have_selector("//p", :count => 6)
40
- expect(@session).not_to have_selector("//p//a[@id='foo']", :count => 2)
41
- expect(@session).not_to have_selector("//p[contains(.,'est')]", :count => 5)
44
+ expect(@session).not_to have_selector("//p", count: 6)
45
+ expect(@session).not_to have_selector("//p//a[@id='foo']", count: 2)
46
+ expect(@session).not_to have_selector("//p[contains(.,'est')]", count: 5)
42
47
  end
43
48
 
44
49
  it "should be false if the content isn't on the page at all" do
45
- expect(@session).not_to have_selector("//abbr", :count => 2)
46
- expect(@session).not_to have_selector("//p//a[@id='doesnotexist']", :count => 1)
50
+ expect(@session).not_to have_selector("//abbr", count: 2)
51
+ expect(@session).not_to have_selector("//p//a[@id='doesnotexist']", count: 1)
47
52
  end
48
53
  end
49
54
 
50
55
  context "with text" do
51
56
  it "should discard all matches where the given string is not contained" do
52
- expect(@session).to have_selector("//p//a", :text => "Redirect", :count => 1)
53
- expect(@session).not_to have_selector("//p", :text => "Doesnotexist")
57
+ expect(@session).to have_selector("//p//a", text: "Redirect", count: 1)
58
+ expect(@session).not_to have_selector("//p", text: "Doesnotexist")
54
59
  end
55
60
 
56
61
  it "should respect visibility setting" do
57
- expect(@session).to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
58
- expect(@session).not_to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
62
+ expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
63
+ expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
59
64
  Capybara.ignore_hidden_elements = false
60
- expect(@session).to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
65
+ expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
61
66
  Capybara.visible_text_only = true
62
- expect(@session).not_to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
67
+ expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
63
68
  end
64
69
 
65
70
  it "should discard all matches where the given regexp is not matched" do
66
- expect(@session).to have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
67
- expect(@session).not_to have_selector("//p//a", :text => /Red$/)
71
+ expect(@session).to have_selector("//p//a", text: /re[dab]i/i, count: 1)
72
+ expect(@session).not_to have_selector("//p//a", text: /Red$/)
73
+ end
74
+
75
+ it "should warn when extra parameters passed" do
76
+ expect_any_instance_of(Kernel).to receive(:warn).with(/extra/)
77
+ expect(@session).to have_selector(:css, "p a#foo", 'extra')
78
+ end
79
+ end
80
+
81
+ context "with exact_text" do
82
+ context "string" do
83
+ it "should only match elements that match exactly" do
84
+ expect(@session).to have_selector(:id, "h2one", exact_text: "Header Class Test One")
85
+ expect(@session).to have_no_selector(:id, "h2one", exact_text: "Header Class Test")
86
+ end
87
+ end
88
+
89
+ context "boolean" do
90
+ it "should only match elements that match exactly when true" do
91
+ expect(@session).to have_selector(:id, "h2one", text: "Header Class Test One", exact_text: true)
92
+ expect(@session).to have_no_selector(:id, "h2one", text: "Header Class Test", exact_text: true)
93
+ end
94
+
95
+ it "should match substrings when false" do
96
+ expect(@session).to have_selector(:id, "h2one", text: "Header Class Test One", exact_text: false)
97
+ expect(@session).to have_selector(:id, "h2one", text: "Header Class Test", exact_text: false)
98
+ end
68
99
  end
69
100
  end
70
101
  end
@@ -99,34 +130,39 @@ Capybara::SpecHelper.spec '#has_no_selector?' do
99
130
  end
100
131
  end
101
132
 
133
+ it "should accept a filter block" do
134
+ skip "RSpec < 3 doesn't pass the block along to the matcher for the Builtin::Has matcher" if rspec2?
135
+ expect(@session).to have_no_selector(:css, "a#foo") { |el| el[:id] != "foo" }
136
+ end
137
+
102
138
  context "with count" do
103
139
  it "should be false if the content is on the page the given number of times" do
104
- expect(@session).not_to have_no_selector("//p", :count => 3)
105
- expect(@session).not_to have_no_selector("//p//a[@id='foo']", :count => 1)
106
- expect(@session).not_to have_no_selector("//p[contains(.,'est')]", :count => 1)
140
+ expect(@session).not_to have_no_selector("//p", count: 3)
141
+ expect(@session).not_to have_no_selector("//p//a[@id='foo']", count: 1)
142
+ expect(@session).not_to have_no_selector("//p[contains(.,'est')]", count: 1)
107
143
  end
108
144
 
109
145
  it "should be true if the content is on the page the wrong number of times" do
110
- expect(@session).to have_no_selector("//p", :count => 6)
111
- expect(@session).to have_no_selector("//p//a[@id='foo']", :count => 2)
112
- expect(@session).to have_no_selector("//p[contains(.,'est')]", :count => 5)
146
+ expect(@session).to have_no_selector("//p", count: 6)
147
+ expect(@session).to have_no_selector("//p//a[@id='foo']", count: 2)
148
+ expect(@session).to have_no_selector("//p[contains(.,'est')]", count: 5)
113
149
  end
114
150
 
115
151
  it "should be true if the content isn't on the page at all" do
116
- expect(@session).to have_no_selector("//abbr", :count => 2)
117
- expect(@session).to have_no_selector("//p//a[@id='doesnotexist']", :count => 1)
152
+ expect(@session).to have_no_selector("//abbr", count: 2)
153
+ expect(@session).to have_no_selector("//p//a[@id='doesnotexist']", count: 1)
118
154
  end
119
155
  end
120
156
 
121
157
  context "with text" do
122
158
  it "should discard all matches where the given string is contained" do
123
- expect(@session).not_to have_no_selector("//p//a", :text => "Redirect", :count => 1)
124
- expect(@session).to have_no_selector("//p", :text => "Doesnotexist")
159
+ expect(@session).not_to have_no_selector("//p//a", text: "Redirect", count: 1)
160
+ expect(@session).to have_no_selector("//p", text: "Doesnotexist")
125
161
  end
126
162
 
127
163
  it "should discard all matches where the given regexp is matched" do
128
- expect(@session).not_to have_no_selector("//p//a", :text => /re[dab]i/i, :count => 1)
129
- expect(@session).to have_no_selector("//p//a", :text => /Red$/)
164
+ expect(@session).not_to have_no_selector("//p//a", text: /re[dab]i/i, count: 1)
165
+ expect(@session).to have_no_selector("//p//a", text: /Red$/)
130
166
  end
131
167
  end
132
168
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_table?' do
2
3
  before do
3
4
  @session.visit('/tables')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_text?' do
2
3
  it "should be true if the given text is on the page at least once" do
3
4
  @session.visit('/with_html')
@@ -79,7 +80,7 @@ Capybara::SpecHelper.spec '#has_text?' do
79
80
  expect(@session).to have_text(:all, 'Some of this text is hidden!')
80
81
  end
81
82
 
82
- it "should be true if `Capybara.ignore_hidden_elements = true` and text is invisible." do
83
+ it "should be true if `Capybara.ignore_hidden_elements = false` and text is invisible." do
83
84
  Capybara.ignore_hidden_elements = false
84
85
  @session.visit('/with_html')
85
86
  expect(@session).to have_text('Some of this text is hidden!')
@@ -95,6 +96,18 @@ Capybara::SpecHelper.spec '#has_text?' do
95
96
  expect(@session).not_to have_text(/xxxxyzzz/)
96
97
  end
97
98
 
99
+ context "with exact: true option" do
100
+ it "should be true if text matches exactly" do
101
+ @session.visit('/with_html')
102
+ expect(@session.find(:id, "h2one")).to have_text("Header Class Test One", exact: true)
103
+ end
104
+
105
+ it "should be false if text doesn't match exactly" do
106
+ @session.visit('/with_html')
107
+ expect(@session.find(:id, "h2one")).not_to have_text("Header Class Test On", exact: true)
108
+ end
109
+ end
110
+
98
111
  it "should escape any characters that would have special meaning in a regexp" do
99
112
  @session.visit('/with_html')
100
113
  expect(@session).not_to have_text('.orem')
@@ -111,10 +124,12 @@ Capybara::SpecHelper.spec '#has_text?' do
111
124
  expect(@session).to have_text(nil)
112
125
  end
113
126
 
114
- it "should wait for text to appear", :requires => [:js] do
115
- @session.visit('/with_js')
116
- @session.click_link('Click me')
117
- expect(@session).to have_text("Has been clicked")
127
+ it "should wait for text to appear", requires: [:js] do
128
+ Capybara.using_wait_time(3) do
129
+ @session.visit('/with_js')
130
+ @session.click_link('Click me')
131
+ expect(@session).to have_text("Has been clicked")
132
+ end
118
133
  end
119
134
 
120
135
  context "with between" do
@@ -191,12 +206,12 @@ Capybara::SpecHelper.spec '#has_text?' do
191
206
  end
192
207
  end
193
208
 
194
- context "with wait", :requires => [:js] do
209
+ context "with wait", requires: [:js] do
195
210
  it "should find element if it appears before given wait duration" do
196
211
  Capybara.using_wait_time(0.1) do
197
212
  @session.visit('/with_js')
198
213
  @session.click_link('Click me')
199
- expect(@session).to have_text('Has been clicked', :wait => 0.9)
214
+ expect(@session).to have_text('Has been clicked', wait: 0.9)
200
215
  end
201
216
  end
202
217
  end
@@ -204,7 +219,7 @@ Capybara::SpecHelper.spec '#has_text?' do
204
219
  it "should raise an error if an invalid option is passed" do
205
220
  @session.visit('/with_html')
206
221
  expect do
207
- expect(@session).to have_text('Lorem', exact: true)
222
+ expect(@session).to have_text('Lorem', invalid: true)
208
223
  end.to raise_error(ArgumentError)
209
224
  end
210
225
  end
@@ -279,7 +294,7 @@ Capybara::SpecHelper.spec '#has_no_text?' do
279
294
  expect(@session).not_to have_no_text(:all, 'Some of this text is hidden!')
280
295
  end
281
296
 
282
- it "should be false if `Capybara.ignore_hidden_elements = true` and text is invisible." do
297
+ it "should be false if `Capybara.ignore_hidden_elements = false` and text is invisible." do
283
298
  Capybara.ignore_hidden_elements = false
284
299
  @session.visit('/with_html')
285
300
  expect(@session).not_to have_no_text('Some of this text is hidden!')
@@ -300,17 +315,17 @@ Capybara::SpecHelper.spec '#has_no_text?' do
300
315
  expect(@session).to have_no_text('.orem')
301
316
  end
302
317
 
303
- it "should wait for text to disappear", :requires => [:js] do
318
+ it "should wait for text to disappear", requires: [:js] do
304
319
  @session.visit('/with_js')
305
320
  @session.click_link('Click me')
306
321
  expect(@session).to have_no_text("I changed it")
307
322
  end
308
323
 
309
- context "with wait", :requires => [:js] do
324
+ context "with wait", requires: [:js] do
310
325
  it "should not find element if it appears after given wait duration" do
311
326
  @session.visit('/with_js')
312
327
  @session.click_link('Click me')
313
- expect(@session).to have_no_text('Has been clicked', :wait => 0.1)
328
+ expect(@session).to have_no_text('Has been clicked', wait: 0.1)
314
329
  end
315
330
  end
316
331
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_title?' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -12,7 +13,7 @@ Capybara::SpecHelper.spec '#has_title?' do
12
13
  expect(@session).not_to have_title(/monkey/)
13
14
  end
14
15
 
15
- it "should wait for title", :requires => [:js] do
16
+ it "should wait for title", requires: [:js] do
16
17
  @session.click_link("Change title")
17
18
  expect(@session).to have_title("changed title")
18
19
  end
@@ -20,6 +21,21 @@ Capybara::SpecHelper.spec '#has_title?' do
20
21
  it "should be false if the page has not the given title" do
21
22
  expect(@session).not_to have_title('monkey')
22
23
  end
24
+
25
+ it "should default to exact: false matching" do
26
+ expect(@session).to have_title('with_js', exact: false)
27
+ expect(@session).to have_title('with_', exact: false)
28
+ end
29
+
30
+ it "should match exactly if exact: true option passed" do
31
+ expect(@session).to have_title('with_js', exact: true)
32
+ expect(@session).not_to have_title('with_', exact: true)
33
+ end
34
+
35
+ it "should match partial if exact: false option passed" do
36
+ expect(@session).to have_title('with_js', exact: false)
37
+ expect(@session).to have_title('with_', exact: false)
38
+ end
23
39
  end
24
40
 
25
41
  Capybara::SpecHelper.spec '#has_no_title?' do
@@ -36,9 +52,11 @@ Capybara::SpecHelper.spec '#has_no_title?' do
36
52
  expect(@session).to have_no_title(/monkey/)
37
53
  end
38
54
 
39
- it "should wait for title to disappear", :requires => [:js] do
40
- @session.click_link("Change title")
41
- expect(@session).to have_no_title('with_js')
55
+ it "should wait for title to disappear", requires: [:js] do
56
+ Capybara.using_wait_time(5) do
57
+ @session.click_link("Change title") # triggers title change after 400ms
58
+ expect(@session).to have_no_title('with_js')
59
+ end
42
60
  end
43
61
 
44
62
  it "should be true if the page has not the given title" do