capybara 2.15.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +137 -2
  3. data/README.md +36 -25
  4. data/lib/capybara/config.rb +11 -57
  5. data/lib/capybara/cucumber.rb +2 -3
  6. data/lib/capybara/driver/base.rb +19 -16
  7. data/lib/capybara/driver/node.rb +5 -4
  8. data/lib/capybara/dsl.rb +1 -0
  9. data/lib/capybara/helpers.rb +19 -29
  10. data/lib/capybara/minitest/spec.rb +16 -13
  11. data/lib/capybara/minitest.rb +140 -137
  12. data/lib/capybara/node/actions.rb +68 -89
  13. data/lib/capybara/node/base.rb +11 -18
  14. data/lib/capybara/node/document.rb +2 -2
  15. data/lib/capybara/node/document_matchers.rb +8 -8
  16. data/lib/capybara/node/element.rb +32 -42
  17. data/lib/capybara/node/finders.rb +64 -71
  18. data/lib/capybara/node/matchers.rb +50 -71
  19. data/lib/capybara/node/simple.rb +11 -17
  20. data/lib/capybara/queries/ancestor_query.rb +12 -8
  21. data/lib/capybara/queries/base_query.rb +22 -18
  22. data/lib/capybara/queries/current_path_query.rb +12 -25
  23. data/lib/capybara/queries/match_query.rb +3 -7
  24. data/lib/capybara/queries/selector_query.rb +100 -96
  25. data/lib/capybara/queries/sibling_query.rb +5 -5
  26. data/lib/capybara/queries/text_query.rb +35 -35
  27. data/lib/capybara/queries/title_query.rb +8 -11
  28. data/lib/capybara/rack_test/browser.rb +15 -18
  29. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  30. data/lib/capybara/rack_test/driver.rb +6 -10
  31. data/lib/capybara/rack_test/form.rb +52 -39
  32. data/lib/capybara/rack_test/node.rb +93 -63
  33. data/lib/capybara/rails.rb +2 -6
  34. data/lib/capybara/result.rb +22 -22
  35. data/lib/capybara/rspec/compound.rb +5 -10
  36. data/lib/capybara/rspec/features.rb +17 -48
  37. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  38. data/lib/capybara/rspec/matchers.rb +116 -58
  39. data/lib/capybara/rspec.rb +5 -10
  40. data/lib/capybara/selector/css.rb +6 -11
  41. data/lib/capybara/selector/filter.rb +1 -17
  42. data/lib/capybara/selector/filter_set.rb +18 -15
  43. data/lib/capybara/selector/filters/base.rb +7 -6
  44. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  45. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  46. data/lib/capybara/selector/selector.rb +28 -34
  47. data/lib/capybara/selector.rb +129 -117
  48. data/lib/capybara/selenium/driver.rb +172 -163
  49. data/lib/capybara/selenium/node.rb +218 -104
  50. data/lib/capybara/server.rb +3 -2
  51. data/lib/capybara/session/config.rb +47 -59
  52. data/lib/capybara/session/matchers.rb +23 -14
  53. data/lib/capybara/session.rb +175 -229
  54. data/lib/capybara/spec/fixtures/no_extension +1 -0
  55. data/lib/capybara/spec/public/test.js +38 -6
  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 +30 -1
  59. data/lib/capybara/spec/session/all_spec.rb +31 -18
  60. data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
  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 +31 -23
  65. data/lib/capybara/spec/session/assert_title.rb +13 -3
  66. data/lib/capybara/spec/session/attach_file_spec.rb +57 -29
  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 +24 -32
  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 +19 -8
  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 +23 -0
  81. data/lib/capybara/spec/session/evaluate_script_spec.rb +5 -4
  82. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  83. data/lib/capybara/spec/session/fill_in_spec.rb +30 -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 +9 -15
  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/frame_title_spec.rb +23 -0
  91. data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  92. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  93. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  94. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  95. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  96. data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  97. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  98. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  99. data/lib/capybara/spec/session/has_current_path_spec.rb +49 -22
  100. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  101. data/lib/capybara/spec/session/has_link_spec.rb +5 -4
  102. data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
  103. data/lib/capybara/spec/session/has_select_spec.rb +32 -31
  104. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  105. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  106. data/lib/capybara/spec/session/has_text_spec.rb +9 -13
  107. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  108. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  109. data/lib/capybara/spec/session/headers.rb +2 -1
  110. data/lib/capybara/spec/session/html_spec.rb +1 -0
  111. data/lib/capybara/spec/session/node_spec.rb +107 -58
  112. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  113. data/lib/capybara/spec/session/refresh_spec.rb +6 -2
  114. data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
  115. data/lib/capybara/spec/session/response_code.rb +1 -0
  116. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  117. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  118. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  119. data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
  120. data/lib/capybara/spec/session/select_spec.rb +21 -20
  121. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  122. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  123. data/lib/capybara/spec/session/text_spec.rb +17 -3
  124. data/lib/capybara/spec/session/title_spec.rb +11 -1
  125. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  126. data/lib/capybara/spec/session/unselect_spec.rb +7 -6
  127. data/lib/capybara/spec/session/visit_spec.rb +64 -3
  128. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  129. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  130. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  131. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  132. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  133. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  134. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  135. data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
  136. data/lib/capybara/spec/session/within_spec.rb +1 -0
  137. data/lib/capybara/spec/spec_helper.rb +36 -18
  138. data/lib/capybara/spec/test_app.rb +17 -9
  139. data/lib/capybara/spec/views/form.erb +7 -0
  140. data/lib/capybara/spec/views/initial_alert.erb +10 -0
  141. data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
  142. data/lib/capybara/spec/views/with_hover.erb +5 -0
  143. data/lib/capybara/spec/views/with_html.erb +27 -1
  144. data/lib/capybara/spec/views/with_js.erb +11 -0
  145. data/lib/capybara/spec/views/within_frames.erb +4 -1
  146. data/lib/capybara/version.rb +2 -1
  147. data/lib/capybara/window.rb +6 -10
  148. data/lib/capybara.rb +29 -26
  149. data/spec/basic_node_spec.rb +1 -0
  150. data/spec/capybara_spec.rb +16 -69
  151. data/spec/dsl_spec.rb +5 -13
  152. data/spec/filter_set_spec.rb +5 -4
  153. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  154. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  155. data/spec/minitest_spec.rb +13 -4
  156. data/spec/minitest_spec_spec.rb +12 -3
  157. data/spec/per_session_config_spec.rb +9 -8
  158. data/spec/rack_test_spec.rb +21 -20
  159. data/spec/result_spec.rb +17 -16
  160. data/spec/rspec/features_spec.rb +17 -14
  161. data/spec/rspec/scenarios_spec.rb +5 -7
  162. data/spec/rspec/shared_spec_matchers.rb +96 -99
  163. data/spec/rspec/views_spec.rb +2 -1
  164. data/spec/rspec_matchers_spec.rb +18 -2
  165. data/spec/rspec_spec.rb +11 -15
  166. data/spec/selector_spec.rb +5 -6
  167. data/spec/selenium_spec_chrome.rb +20 -11
  168. data/spec/selenium_spec_edge.rb +27 -0
  169. data/spec/selenium_spec_ie.rb +31 -0
  170. data/spec/selenium_spec_marionette.rb +38 -12
  171. data/spec/server_spec.rb +33 -33
  172. data/spec/session_spec.rb +2 -1
  173. data/spec/shared_selenium_session.rb +82 -22
  174. data/spec/spec_helper.rb +3 -6
  175. metadata +76 -81
  176. data/lib/capybara/query.rb +0 -7
  177. data/spec/selenium_spec_firefox.rb +0 -68
data/spec/result_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe Capybara::Result do
@@ -14,7 +15,7 @@ RSpec.describe Capybara::Result do
14
15
  end
15
16
 
16
17
  let :result do
17
- string.all '//li'
18
+ string.all '//li', minimum: 0 # pass minimum: 0 so lazy evaluation doesn't get triggered yet
18
19
  end
19
20
 
20
21
  it "has a length" do
@@ -30,7 +31,7 @@ RSpec.describe Capybara::Result do
30
31
  end
31
32
 
32
33
  it 'can supports values_at method' do
33
- expect(result.values_at(0, 2).map(&:text)).to eq(%w(Alpha Gamma))
34
+ expect(result.values_at(0, 2).map(&:text)).to eq(%w[Alpha Gamma])
34
35
  end
35
36
 
36
37
  it "can return an element by its index" do
@@ -39,7 +40,7 @@ RSpec.describe Capybara::Result do
39
40
  end
40
41
 
41
42
  it "can be mapped" do
42
- expect(result.map(&:text)).to eq(%w(Alpha Beta Gamma Delta))
43
+ expect(result.map(&:text)).to eq(%w[Alpha Beta Gamma Delta])
43
44
  end
44
45
 
45
46
  it "can be selected" do
@@ -50,7 +51,7 @@ RSpec.describe Capybara::Result do
50
51
 
51
52
  it "can be reduced" do
52
53
  expect(result.reduce('') do |memo, element|
53
- memo += element.text[0]
54
+ memo + element.text[0]
54
55
  end).to eq('ABGD')
55
56
  end
56
57
 
@@ -66,8 +67,8 @@ RSpec.describe Capybara::Result do
66
67
 
67
68
  it 'supports all modes of []' do
68
69
  expect(result[1].text).to eq 'Beta'
69
- expect(result[0,2].map(&:text)).to eq ['Alpha', 'Beta']
70
- expect(result[1..3].map(&:text)).to eq ['Beta', 'Gamma', 'Delta']
70
+ expect(result[0, 2].map(&:text)).to eq %w[Alpha Beta]
71
+ expect(result[1..3].map(&:text)).to eq %w[Beta Gamma Delta]
71
72
  expect(result[-1].text).to eq 'Delta'
72
73
  end
73
74
 
@@ -78,37 +79,37 @@ RSpec.describe Capybara::Result do
78
79
 
79
80
  it 'should catch invalid element errors during filtering' do
80
81
  allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
81
- allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError] )))
82
+ allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError])))
82
83
  result = string.all('//li', text: 'Alpha')
83
84
  expect(result.size).to eq 0
84
85
  end
85
86
 
86
87
  it 'should return non-invalid element errors during filtering' do
87
88
  allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
88
- allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError] )))
89
+ allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError])))
89
90
  expect do
90
91
  string.all('//li', text: 'Alpha').to_a
91
92
  end.to raise_error(StandardError)
92
93
  end
93
94
 
94
- #Not a great test but it indirectly tests what is needed
95
+ # Not a great test but it indirectly tests what is needed
95
96
  it "should evaluate filters lazily" do
96
97
  skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
97
- #Not processed until accessed
98
+ # Not processed until accessed
98
99
  expect(result.instance_variable_get('@result_cache').size).to be 0
99
100
 
100
- #Only one retrieved when needed
101
+ # Only one retrieved when needed
101
102
  result.first
102
103
  expect(result.instance_variable_get('@result_cache').size).to be 1
103
104
 
104
- #works for indexed access
105
+ # works for indexed access
105
106
  result[0]
106
107
  expect(result.instance_variable_get('@result_cache').size).to be 1
107
108
 
108
109
  result[2]
109
110
  expect(result.instance_variable_get('@result_cache').size).to be 3
110
111
 
111
- #All cached when converted to array
112
+ # All cached when converted to array
112
113
  result.to_a
113
114
  expect(result.instance_variable_get('@result_cache').size).to eq 4
114
115
  end
@@ -116,7 +117,7 @@ RSpec.describe Capybara::Result do
116
117
  context '#each' do
117
118
  it 'lazily evaluates' do
118
119
  skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
119
- results=[]
120
+ results = []
120
121
  result.each do |el|
121
122
  results << el
122
123
  expect(result.instance_variable_get('@result_cache').size).to eq results.size
@@ -132,8 +133,8 @@ RSpec.describe Capybara::Result do
132
133
 
133
134
  it 'lazily evaluates' do
134
135
  skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
135
- result.each.with_index do |el, idx|
136
- expect(result.instance_variable_get('@result_cache').size).to eq(idx+1) # 0 indexing
136
+ result.each.with_index do |_el, idx|
137
+ expect(result.instance_variable_get('@result_cache').size).to eq(idx + 1) # 0 indexing
137
138
  end
138
139
  end
139
140
  end
@@ -1,8 +1,9 @@
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/features_spec.rb" } ) do
6
+ RSpec.configuration.before(:each, file_path: "./spec/rspec/features_spec.rb") do
6
7
  @in_filtered_hook = true
7
8
  end
8
9
 
@@ -25,7 +26,7 @@ feature "Capybara's feature DSL" do
25
26
  .to eq("Capybara's feature DSL preserves description")
26
27
  end
27
28
 
28
- scenario "allows driver switching", :driver => :selenium do
29
+ scenario "allows driver switching", driver: :selenium do
29
30
  expect(Capybara.current_driver).to eq(:selenium)
30
31
  end
31
32
 
@@ -71,25 +72,27 @@ feature "given and given! aliases to let and let!" do
71
72
  end
72
73
  end
73
74
 
74
- feature "Capybara's feature DSL with driver", :driver => :culerity do
75
+ feature "Capybara's feature DSL with driver", driver: :culerity do
75
76
  scenario "switches driver" do
76
77
  expect(Capybara.current_driver).to eq(:culerity)
77
78
  end
78
79
  end
79
80
 
80
- if RSpec::Core::Version::STRING.to_f >= 3.0
81
- xfeature "if xfeature aliases to pending then" do
82
- scenario "this should be 'temporarily disabled with xfeature'" do; end
83
- scenario "this also should be 'temporarily disabled with xfeature'" do; end
81
+ xfeature "if xfeature aliases to pending then" do
82
+ scenario "this should be 'temporarily disabled with xfeature'" do
83
+ # dummy
84
+ end
85
+ scenario "this also should be 'temporarily disabled with xfeature'" do
86
+ # dummy
84
87
  end
88
+ end
85
89
 
86
- ffeature "if ffeature aliases focused tag then" do
87
- scenario "scenario inside this feature has metatag focus tag" do |example|
88
- expect(example.metadata[:focus]).to eq true
89
- end
90
+ ffeature "if ffeature aliases focused tag then" do
91
+ scenario "scenario inside this feature has metatag focus tag" do |example|
92
+ expect(example.metadata[:focus]).to eq true
93
+ end
90
94
 
91
- scenario "other scenarios also has metatag focus tag " do |example|
92
- expect(example.metadata[:focus]).to eq true
93
- end
95
+ scenario "other scenarios also has metatag focus tag " do |example|
96
+ expect(example.metadata[:focus]).to eq true
94
97
  end
95
98
  end
@@ -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,17 @@ 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
+ expect(not_to_msg).to eq have_no_msg
30
+ end
19
31
  end
20
32
 
21
33
  context "after called on element" do
@@ -43,4 +55,8 @@ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
43
55
  expect { matcher.description }.not_to raise_error
44
56
  end
45
57
  end
46
- end
58
+
59
+ def error_msg_for(&block)
60
+ expect(&block).to(raise_error { |e| return e.message })
61
+ end
62
+ end