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,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'capybara/rspec'
4
5
 
5
- RSpec.configuration.before(:each, { file_path: "./spec/rspec/scenarios_spec.rb" } ) do
6
+ RSpec.configuration.before(:each, file_path: "./spec/rspec/scenarios_spec.rb") do
6
7
  @in_filtered_hook = true
7
8
  end
8
9
 
9
- if RSpec::Core::Version::STRING.to_f >= 3.0
10
- feature "if fscenario aliases focused tag then" do
11
- fscenario "scenario should have focused meta tag" do |example|
12
- expect(example.metadata[:focus]).to eq true
13
- end
10
+ feature "if fscenario aliases focused tag then" do
11
+ fscenario "scenario should have focused meta tag" do |example|
12
+ expect(example.metadata[:focus]).to eq true
14
13
  end
15
14
  end
16
15
 
@@ -18,4 +17,3 @@ feature "if xscenario aliases to pending then" do
18
17
  xscenario "this test should be 'temporarily disabled with xscenario'" do
19
18
  end
20
19
  end
21
-
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'capybara/dsl'
4
5
  require 'capybara/rspec/matchers'
5
6
  require 'benchmark'
6
7
 
7
- RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
8
-
8
+ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
9
9
  include Capybara::DSL
10
10
  include Capybara::RSpecMatchers
11
11
 
@@ -53,7 +53,6 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
53
53
  expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
54
54
  end.to raise_error("expected to find visible css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
55
55
  end
56
-
57
56
  end
58
57
 
59
58
  context "with should_not" do
@@ -81,7 +80,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
81
80
  it "supports compounding" do
82
81
  expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
83
82
  expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
84
- end if RSpec::Version::STRING.to_f >= 3.0
83
+ end
85
84
  end
86
85
 
87
86
  context "on a page or node" do
@@ -129,7 +128,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
129
128
  it "fails if has_xpath? returns false" do
130
129
  expect do
131
130
  expect("<h1>Text</h1>").to have_xpath('//h2')
132
- end.to raise_error(%r(expected to find visible xpath "//h2" but there were no matches))
131
+ end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
133
132
  end
134
133
  end
135
134
 
@@ -141,14 +140,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
141
140
  it "fails if has_no_xpath? returns false" do
142
141
  expect do
143
142
  expect("<h1>Text</h1>").not_to have_xpath('//h1')
144
- end.to raise_error(%r(expected not to find visible xpath "//h1"))
143
+ end.to raise_error(%r{expected not to find visible xpath "//h1"})
145
144
  end
146
145
  end
147
146
 
148
147
  it "supports compounding" do
149
148
  expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
150
149
  expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
151
- end if RSpec::Version::STRING.to_f >= 3.0
150
+ end
152
151
  end
153
152
 
154
153
  context "on a page or node" do
@@ -164,7 +163,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
164
163
  it "fails if has_xpath? returns false" do
165
164
  expect do
166
165
  expect(page).to have_xpath("//h1[@id='doesnotexist']")
167
- end.to raise_error(%r(expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
166
+ end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
168
167
  end
169
168
  end
170
169
 
@@ -176,7 +175,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
176
175
  it "fails if has_no_xpath? returns false" do
177
176
  expect do
178
177
  expect(page).not_to have_xpath('//h1')
179
- end.to raise_error(%r(expected not to find visible xpath "//h1"))
178
+ end.to raise_error(%r{expected not to find visible xpath "//h1"})
180
179
  end
181
180
  end
182
181
  end
@@ -198,7 +197,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
198
197
  it "fails if has_selector? returns false" do
199
198
  expect do
200
199
  expect("<h1>Text</h1>").to have_selector('//h2')
201
- end.to raise_error(%r(expected to find visible xpath "//h2" but there were no matches))
200
+ end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
202
201
  end
203
202
  end
204
203
 
@@ -210,7 +209,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
210
209
  it "fails if has_no_selector? returns false" do
211
210
  expect do
212
211
  expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
213
- end.to raise_error(%r(expected not to find visible css "h1"))
212
+ end.to raise_error(%r{expected not to find visible css "h1"})
214
213
  end
215
214
  end
216
215
  end
@@ -228,13 +227,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
228
227
  it "fails if has_selector? returns false" do
229
228
  expect do
230
229
  expect(page).to have_selector("//h1[@id='doesnotexist']")
231
- end.to raise_error(%r(expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
230
+ end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
232
231
  end
233
232
 
234
233
  it "includes text in error message" do
235
234
  expect do
236
235
  expect(page).to have_selector("//h1", text: 'wrong text')
237
- end.to raise_error(%r(expected to find visible xpath "//h1" with text "wrong text" but there were no matches))
236
+ end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
238
237
  end
239
238
  end
240
239
 
@@ -246,7 +245,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
246
245
  it "fails if has_no_selector? returns false" do
247
246
  expect do
248
247
  expect(page).not_to have_selector(:css, 'h1', text: 'test')
249
- end.to raise_error(%r(expected not to find visible css "h1" with text "test"))
248
+ end.to raise_error(%r{expected not to find visible css "h1" with text "test"})
250
249
  end
251
250
  end
252
251
  end
@@ -254,7 +253,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
254
253
  it "supports compounding" do
255
254
  expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
256
255
  expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
257
- end if RSpec::Version::STRING.to_f >= 3.0
256
+ end
258
257
  end
259
258
 
260
259
  describe "have_content matcher" do
@@ -343,7 +342,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
343
342
  it "supports compounding" do
344
343
  expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
345
344
  expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
346
- end if RSpec::Version::STRING.to_f >= 3.0
345
+ end
347
346
  end
348
347
 
349
348
  describe "have_text matcher" do
@@ -477,7 +476,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
477
476
  it "supports compounding" do
478
477
  expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
479
478
  expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
480
- end if RSpec::Version::STRING.to_f >= 3.0
479
+ end
481
480
  end
482
481
 
483
482
  describe "have_link matcher" do
@@ -500,7 +499,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
500
499
  it "supports compounding" do
501
500
  expect(html).to have_link('Just a link').and have_link('Another link')
502
501
  expect(html).to have_link('Not a link').or have_link('Another link')
503
- end if RSpec::Version::STRING.to_f >= 3.0
502
+ end
504
503
  end
505
504
 
506
505
  describe "have_title matcher" do
@@ -565,7 +564,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
565
564
 
566
565
  it "supports compounding" do
567
566
  expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
568
- end if RSpec::Version::STRING.to_f >= 3.0
567
+ end
569
568
  end
570
569
 
571
570
  describe "have_current_path matcher" do
@@ -611,7 +610,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
611
610
  it "supports compounding" do
612
611
  visit('/with_html')
613
612
  expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
614
- end if RSpec::Version::STRING.to_f >= 3.0
613
+ end
615
614
  end
616
615
 
617
616
  describe "have_button matcher" do
@@ -633,7 +632,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
633
632
 
634
633
  it "supports compounding" do
635
634
  expect(html).to have_button('Not this button').or have_button('A button')
636
- end if RSpec::Version::STRING.to_f >= 3.0
635
+ end
637
636
  end
638
637
 
639
638
  describe "have_field matcher" do
@@ -678,7 +677,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
678
677
 
679
678
  it "supports compounding" do
680
679
  expect(html).to have_field('Not this one').or have_field('Text field')
681
- end if RSpec::Version::STRING.to_f >= 3.0
680
+ end
682
681
  end
683
682
 
684
683
  describe "have_checked_field matcher" do
@@ -727,7 +726,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
727
726
 
728
727
  it "supports compounding" do
729
728
  expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
730
- end if RSpec::Version::STRING.to_f >= 3.0
729
+ end
731
730
  end
732
731
 
733
732
  describe "have_unchecked_field matcher" do
@@ -776,7 +775,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
776
775
 
777
776
  it "supports compounding" do
778
777
  expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
779
- end if RSpec::Version::STRING.to_f >= 3.0
778
+ end
780
779
  end
781
780
 
782
781
  describe "have_select matcher" do
@@ -802,7 +801,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
802
801
 
803
802
  it "supports compounding" do
804
803
  expect(html).to have_select('Not this one').or have_select('Select Box')
805
- end if RSpec::Version::STRING.to_f >= 3.0
804
+ end
806
805
  end
807
806
 
808
807
  describe "have_table matcher" do
@@ -831,100 +830,98 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
831
830
 
832
831
  it "supports compounding" do
833
832
  expect(html).to have_table('nope').or have_table('Lovely table')
834
- end if RSpec::Version::STRING.to_f >= 3.0
833
+ end
835
834
  end
836
835
 
837
- if RSpec::Version::STRING.to_f >= 3.0
838
- context "compounding", requires: [:js] do
839
- before(:each) do
840
- @session = session
841
- @session.visit('/with_js')
842
- @el = @session.find(:css, '#reload-me')
843
- end
844
-
845
- context "#and" do
846
- it "should run 'concurrently'" do
847
- Capybara.using_wait_time(2) do
848
- matcher = have_text('this is not there').and have_text('neither is this')
849
- expect(Benchmark.realtime do
850
- expect {
851
- expect(@el).to matcher
852
- }.to raise_error RSpec::Expectations::ExpectationNotMetError
853
- end).to be_between(2,3)
854
- end
855
- end
836
+ context "compounding", requires: [:js] do
837
+ before(:each) do
838
+ @session = session
839
+ @session.visit('/with_js')
840
+ @el = @session.find(:css, '#reload-me')
841
+ end
856
842
 
857
- it "should run 'concurrently' and retry" do
858
- @session.click_link('reload-link')
859
- @session.using_wait_time(2) do
860
- expect(Benchmark.realtime do
861
- expect {
862
- expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
863
- }.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
864
- end).to be_between(2,3)
865
- end
843
+ context "#and" do
844
+ it "should run 'concurrently'" do
845
+ Capybara.using_wait_time(2) do
846
+ matcher = have_text('this is not there').and have_text('neither is this')
847
+ expect(Benchmark.realtime do
848
+ expect do
849
+ expect(@el).to matcher
850
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError
851
+ end).to be_between(2, 3)
866
852
  end
853
+ end
867
854
 
868
- it "should ignore :wait options" do
869
- @session.using_wait_time(2) do
870
- matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
871
- expect(Benchmark.realtime do
872
- expect {
873
- expect(@el).to matcher
874
- }.to raise_error RSpec::Expectations::ExpectationNotMetError
875
- end).to be_between(2,3)
876
- end
855
+ it "should run 'concurrently' and retry" do
856
+ @session.click_link('reload-link')
857
+ @session.using_wait_time(2) do
858
+ expect(Benchmark.realtime do
859
+ expect do
860
+ expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
861
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
862
+ end).to be_between(2, 3)
877
863
  end
864
+ end
878
865
 
879
- it "should work on the session" do
880
- @session.using_wait_time(2) do
881
- @session.click_link('reload-link')
882
- expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
883
- end
866
+ it "should ignore :wait options" do
867
+ @session.using_wait_time(2) do
868
+ matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
869
+ expect(Benchmark.realtime do
870
+ expect do
871
+ expect(@el).to matcher
872
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError
873
+ end).to be_between(2, 3)
884
874
  end
885
875
  end
886
876
 
887
- context "#and_then" do
888
- it "should run sequentially" do
877
+ it "should work on the session" do
878
+ @session.using_wait_time(2) do
889
879
  @session.click_link('reload-link')
890
- expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
880
+ expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
891
881
  end
892
882
  end
883
+ end
893
884
 
894
- context "#or" do
895
- it "should run 'concurrently'" do
896
- @session.using_wait_time(3) do
897
- expect(Benchmark.realtime do
898
- expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
899
- end).to be < 1
900
- end
885
+ context "#and_then" do
886
+ it "should run sequentially" do
887
+ @session.click_link('reload-link')
888
+ expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
889
+ end
890
+ end
891
+
892
+ context "#or" do
893
+ it "should run 'concurrently'" do
894
+ @session.using_wait_time(3) do
895
+ expect(Benchmark.realtime do
896
+ expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
897
+ end).to be < 1
901
898
  end
899
+ end
902
900
 
903
- it "should retry" do
904
- @session.using_wait_time(3) do
905
- expect(Benchmark.realtime do
906
- expect {
907
- expect(@el).to have_text('has been reloaded').or have_text('random stuff')
908
- }.to raise_error RSpec::Expectations::ExpectationNotMetError
909
- end).to be > 3
910
- end
901
+ it "should retry" do
902
+ @session.using_wait_time(3) do
903
+ expect(Benchmark.realtime do
904
+ expect do
905
+ expect(@el).to have_text('has been reloaded').or have_text('random stuff')
906
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError
907
+ end).to be > 3
911
908
  end
909
+ end
912
910
 
913
- it "should ignore :wait options" do
914
- @session.using_wait_time(2) do
915
- expect(Benchmark.realtime do
916
- expect {
917
- expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
918
- }.to raise_error RSpec::Expectations::ExpectationNotMetError
919
- end).to be_between(2,3)
920
- end
911
+ it "should ignore :wait options" do
912
+ @session.using_wait_time(2) do
913
+ expect(Benchmark.realtime do
914
+ expect do
915
+ expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
916
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError
917
+ end).to be_between(2, 3)
921
918
  end
919
+ end
922
920
 
923
- it "should work on the session" do
924
- @session.using_wait_time(2) do
925
- @session.click_link('reload-link')
926
- expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
927
- end
921
+ it "should work on the session" do
922
+ @session.using_wait_time(2) do
923
+ @session.click_link('reload-link')
924
+ expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
928
925
  end
929
926
  end
930
927
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe "capybara/rspec", type: :view do
5
6
  it "allows matchers to be used on strings" do
6
- expect(%{<h1>Test header</h1>}).to have_css("h1", text: "Test header")
7
+ expect(%(<h1>Test header</h1>)).to have_css("h1", text: "Test header")
7
8
  end
8
9
 
9
10
  it "doesn't include RSpecMatcherProxies" do
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
- RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
5
+ RSpec.describe 'Capybara RSpec Matchers', type: :feature do
5
6
  context "after called on session" do
6
7
  it "HaveSelector should allow getting a description of the matcher" do
7
8
  visit('/with_html')
@@ -16,6 +17,18 @@ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
16
17
  expect(page).to matcher
17
18
  expect { matcher.description }.not_to raise_error
18
19
  end
20
+
21
+ it "should produce the same error for .to have_no_xxx and .not_to have_xxx" do
22
+ visit('/with_html')
23
+ not_to_msg = error_msg_for { expect(page).not_to have_selector(:css, '#referrer') }
24
+ have_no_msg = error_msg_for { expect(page).to have_no_selector(:css, '#referrer') }
25
+ expect(not_to_msg).to eq have_no_msg
26
+
27
+ not_to_msg = error_msg_for { expect(page).not_to have_text('This is a test') }
28
+ have_no_msg = error_msg_for { expect(page).to have_no_text('This is a test') }
29
+ puts not_to_msg
30
+ expect(not_to_msg).to eq have_no_msg
31
+ end
19
32
  end
20
33
 
21
34
  context "after called on element" do
@@ -43,4 +56,8 @@ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
43
56
  expect { matcher.description }.not_to raise_error
44
57
  end
45
58
  end
46
- end
59
+
60
+ def error_msg_for(&block)
61
+ expect(&block).to(raise_error { |e| return e.message })
62
+ end
63
+ end