capybara 2.15.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,24 +1,25 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "capybara/spec/test_app"
3
4
 
4
5
  Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
5
6
  before :all do
6
- @servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
7
+ @servers = Array.new(2) { Capybara::Server.new(TestApp.new).boot }
7
8
  # sanity check
8
9
  expect(@servers[0].port).not_to eq(@servers[1].port)
9
- expect(@servers.map { |s| s.port }).not_to include 80
10
+ expect(@servers.map(&:port)).not_to include 80
10
11
  end
11
12
 
12
13
  def bases
13
14
  @servers.map { |s| "http://#{s.host}:#{s.port}" }
14
15
  end
15
16
 
16
- def should_be_on server_index, path="/host", scheme="http"
17
- #This delay is to give fully async drivers (selenium w/chromedriver) time for the browser
18
- #to get to its destination - should be removed when we have a waiting current_url matcher
19
- sleep 0.1 # remove and adjust tests when a waiting current_url/path matcher is implemented
17
+ def should_be_on(server_index, path = "/host", scheme = "http")
20
18
  # Check that we are on /host on the given server
21
19
  s = @servers[server_index]
20
+
21
+ expect(@session).to have_current_path("#{scheme}://#{s.host}:#{s.port}#{path}", url: true)
22
+
22
23
  expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
23
24
  expect(@session.current_host).to eq("#{scheme}://#{s.host}") # no port
24
25
  expect(@session.current_path).to eq(path)
@@ -98,10 +99,20 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
98
99
  end
99
100
 
100
101
  it "doesn't raise exception on a nil current_url" do
102
+ skip "Only makes sense when there is a real driver" unless @session.respond_to?(:driver)
103
+ allow(@session.driver).to receive(:current_url) { nil }
101
104
  @session.visit("/")
102
- allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
103
-
104
105
  expect { @session.current_url }.not_to raise_exception
105
106
  expect { @session.current_path }.not_to raise_exception
106
107
  end
108
+
109
+ context "within iframe", requires: [:frames] do
110
+ it "should get the url of the top level browsing context" do
111
+ @session.visit('/within_frames')
112
+ expect(@session.current_url).to match(/within_frames\z/)
113
+ @session.within_frame('frameOne') do
114
+ expect(@session.current_url).to match(/within_frames\z/)
115
+ end
116
+ end
117
+ end
107
118
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -26,7 +27,6 @@ Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
26
27
  end.to raise_error(Capybara::ModalNotFound)
27
28
  end
28
29
 
29
-
30
30
  it "should return the message presented" do
31
31
  message = @session.dismiss_confirm do
32
32
  @session.click_link('Open confirm')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#dismiss_prompt', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -31,6 +31,6 @@ Capybara::SpecHelper.spec '#assert_matches_selector' do
31
31
 
32
32
  it "should accept a filter block" do
33
33
  @element.assert_matches_selector(:css, 'span') { |el| el[:class] == "number" }
34
- @element.assert_not_matches_selector(:css,'span') { |el| el[:class] == "not_number" }
34
+ @element.assert_not_matches_selector(:css, 'span') { |el| el[:class] == "not_number" }
35
35
  end
36
36
  end
@@ -20,4 +20,4 @@ Capybara::SpecHelper.spec '#match_xpath?' do
20
20
  expect(@element).not_to have_xpath("//span[@class='not_a_number']")
21
21
  expect(@element).not_to have_xpath("//div[@class='number']")
22
22
  end
23
- end
23
+ end
@@ -52,10 +52,10 @@ Capybara::SpecHelper.spec '#match_selector?' do
52
52
  it 'should accept a custom filter block' do
53
53
  @session.visit('/form')
54
54
  cbox = @session.find(:css, '#form_pets_dog')
55
- expect(cbox).to match_selector(:checkbox){ |node| node[:id] == "form_pets_dog"}
56
- expect(cbox).not_to match_selector(:checkbox){ |node| node[:id] != "form_pets_dog"}
57
- expect(cbox.matches_selector?(:checkbox){ |node| node[:id] == "form_pets_dog"}).to be true
58
- expect(cbox.matches_selector?(:checkbox){ |node| node[:id] != "form_pets_dog"}).to be false
55
+ expect(cbox).to match_selector(:checkbox) { |node| node[:id] == "form_pets_dog" }
56
+ expect(cbox).not_to match_selector(:checkbox) { |node| node[:id] != "form_pets_dog" }
57
+ expect(cbox.matches_selector?(:checkbox) { |node| node[:id] == "form_pets_dog" }).to be true
58
+ expect(cbox.matches_selector?(:checkbox) { |node| node[:id] != "form_pets_dog" }).to be false
59
59
  end
60
60
  end
61
61
 
@@ -103,4 +103,4 @@ Capybara::SpecHelper.spec '#not_matches_selector?' do
103
103
  expect(@element.not_matches_xpath?("//span", text: "42")).to be false
104
104
  expect(@element.not_matches_xpath?("//span", text: "Doesnotexist")).to be true
105
105
  end
106
- end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')
106
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ Capybara::SpecHelper.spec "#evaluate_async_script", requires: [:js] do
4
+ it "should evaluate the given script and return whatever it produces" do
5
+ @session.visit('/with_js')
6
+ expect(@session.evaluate_async_script("arguments[0](4)")).to eq(4)
7
+ end
8
+
9
+ it "should support passing elements as arguments to the script", requires: %i[js es_args] do
10
+ @session.visit('/with_js')
11
+ el = @session.find(:css, '#drag p')
12
+ result = @session.evaluate_async_script("arguments[2]([arguments[0].innerText, arguments[1]])", el, "Doodle Funk")
13
+ expect(result).to eq ["This is a draggable element.", "Doodle Funk"]
14
+ end
15
+
16
+ it "should support returning elements after asynchronous operation", requires: %i[js es_args] do
17
+ @session.visit('/with_js')
18
+ @session.find(:css, '#change') # ensure page has loaded and element is available
19
+ el = @session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(document.getElementById('change')) }, 100)")
20
+ expect(el).to be_instance_of(Capybara::Node::Element)
21
+ expect(el).to eq(@session.find(:css, '#change'))
22
+ end
23
+ end
@@ -1,26 +1,27 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#evaluate_script", requires: [:js] do
3
4
  it "should evaluate the given script and return whatever it produces" do
4
5
  @session.visit('/with_js')
5
6
  expect(@session.evaluate_script("1+3")).to eq(4)
6
7
  end
7
8
 
8
- it "should pass arguments to the script", requires: [:js, :es_args] do
9
+ it "should pass arguments to the script", requires: %i[js es_args] do
9
10
  @session.visit('/with_js')
10
11
  @session.evaluate_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
11
12
  expect(@session).to have_css('#change', text: 'Doodle Funk')
12
13
  end
13
14
 
14
- it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
15
+ it "should support passing elements as arguments to the script", requires: %i[js es_args] do
15
16
  @session.visit('/with_js')
16
17
  el = @session.find(:css, '#change')
17
18
  @session.evaluate_script("arguments[0].textContent = arguments[1]", el, "Doodle Funk")
18
19
  expect(@session).to have_css('#change', text: 'Doodle Funk')
19
20
  end
20
21
 
21
- it "should support returning elements", requires: [:js, :es_args] do
22
+ it "should support returning elements", requires: %i[js es_args] do
22
23
  @session.visit('/with_js')
23
- el = @session.find(:css, '#change')
24
+ @session.find(:css, '#change') # ensure page has loaded and element is available
24
25
  el = @session.evaluate_script("document.getElementById('change')")
25
26
  expect(el).to be_instance_of(Capybara::Node::Element)
26
27
  expect(el).to eq(@session.find(:css, '#change'))
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
3
4
  it "should execute the given script and return nothing" do
4
5
  @session.visit('/with_js')
@@ -8,16 +9,16 @@ Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
8
9
 
9
10
  it "should be able to call functions defined in the page" do
10
11
  @session.visit('/with_js')
11
- expect{ @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
12
+ expect { @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
12
13
  end
13
14
 
14
- it "should pass arguments to the script", requires: [:js, :es_args] do
15
+ it "should pass arguments to the script", requires: %i[js es_args] do
15
16
  @session.visit('/with_js')
16
17
  @session.execute_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
17
18
  expect(@session).to have_css('#change', text: 'Doodle Funk')
18
19
  end
19
20
 
20
- it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
21
+ it "should support passing elements as arguments to the script", requires: %i[js es_args] do
21
22
  @session.visit('/with_js')
22
23
  el = @session.find(:css, '#change')
23
24
  @session.execute_script("arguments[1].textContent = arguments[0]", "Doodle Funk", el)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#fill_in" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -52,6 +53,30 @@ Capybara::SpecHelper.spec "#fill_in" do
52
53
  expect(extract_results(@session)['password']).to eq('supasikrit')
53
54
  end
54
55
 
56
+ context "Date/Time" do
57
+ it "should fill in a date input" do
58
+ date = Date.today
59
+ @session.fill_in('form_date', with: date)
60
+ @session.click_button('awesome')
61
+ expect(Date.parse(extract_results(@session)['date'])).to eq date
62
+ end
63
+
64
+ it "should fill in a time input" do
65
+ time = Time.new(2018, 3, 9, 15, 26)
66
+ @session.fill_in('form_time', with: time)
67
+ @session.click_button('awesome')
68
+ results = extract_results(@session)['time']
69
+ expect(Time.parse(results).strftime('%r')).to eq time.strftime('%r')
70
+ end
71
+
72
+ it "should fill in a datetime input" do
73
+ dt = Time.new(2018, 3, 13, 9, 53)
74
+ @session.fill_in('form_datetime', with: dt)
75
+ @session.click_button('awesome')
76
+ expect(Time.parse(extract_results(@session)['datetime'])).to eq dt
77
+ end
78
+ end
79
+
55
80
  it "should handle HTML in a textarea" do
56
81
  @session.fill_in('form_description', with: 'is <strong>very</strong> secret!')
57
82
  @session.click_button('awesome')
@@ -113,7 +138,7 @@ Capybara::SpecHelper.spec "#fill_in" do
113
138
  end
114
139
 
115
140
  it "should throw an exception if a hash containing 'with' is not provided" do
116
- expect {@session.fill_in 'Name', 'ignu'}.to raise_error(RuntimeError, /with/)
141
+ expect { @session.fill_in 'Name' }.to raise_error(ArgumentError, /with/)
117
142
  end
118
143
 
119
144
  it "should wait for asynchronous load", requires: [:js] do
@@ -123,13 +148,13 @@ Capybara::SpecHelper.spec "#fill_in" do
123
148
  end
124
149
 
125
150
  it "casts to string" do
126
- @session.fill_in(:'form_first_name', with: :'Harry')
151
+ @session.fill_in(:form_first_name, with: :Harry)
127
152
  @session.click_button('awesome')
128
153
  expect(extract_results(@session)['first_name']).to eq('Harry')
129
154
  end
130
155
 
131
156
  it "casts to string if field has maxlength" do
132
- @session.fill_in(:'form_zipcode', with: 1234567)
157
+ @session.fill_in(:form_zipcode, with: 1234567)
133
158
  @session.click_button('awesome')
134
159
  expect(extract_results(@session)['zipcode']).to eq('12345')
135
160
  end
@@ -182,14 +207,14 @@ Capybara::SpecHelper.spec "#fill_in" do
182
207
 
183
208
  context "with :exact option" do
184
209
  it "should accept partial matches when false" do
185
- @session.fill_in("Explanation", with: "Dude", exact: false)
210
+ @session.fill_in("Explanation", with: "Dude", exact: false)
186
211
  @session.click_button("awesome")
187
212
  expect(extract_results(@session)["name_explanation"]).to eq("Dude")
188
213
  end
189
214
 
190
215
  it "should not accept partial matches when true" do
191
216
  expect do
192
- @session.fill_in("Explanation", with: "Dude", exact: true)
217
+ @session.fill_in("Explanation", with: "Dude", exact: true)
193
218
  end.to raise_error(Capybara::ElementNotFound)
194
219
  end
195
220
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find_button' do
3
4
  before do
4
5
  @session.visit('/form')
@@ -22,7 +23,7 @@ Capybara::SpecHelper.spec '#find_button' do
22
23
  end
23
24
 
24
25
  it "casts to string" do
25
- expect(@session.find_button(:'med')[:id]).to eq("mediocre")
26
+ expect(@session.find_button(:med)[:id]).to eq("mediocre")
26
27
  end
27
28
 
28
29
  it "should raise error if the button doesn't exist" do
@@ -33,12 +34,12 @@ Capybara::SpecHelper.spec '#find_button' do
33
34
 
34
35
  context "with :exact option" do
35
36
  it "should accept partial matches when false" do
36
- expect(@session.find_button('What an Awesome', exact: false).value).to eq("awesome")
37
+ expect(@session.find_button('What an Awesome', exact: false).value).to eq("awesome")
37
38
  end
38
39
 
39
40
  it "should not accept partial matches when true" do
40
41
  expect do
41
- @session.find_button('What an Awesome', exact: true)
42
+ @session.find_button('What an Awesome', exact: true)
42
43
  end.to raise_error(Capybara::ElementNotFound)
43
44
  end
44
45
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find_by_id' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -9,7 +10,7 @@ Capybara::SpecHelper.spec '#find_by_id' do
9
10
  end
10
11
 
11
12
  it "casts to string" do
12
- expect(@session.find_by_id(:'red').tag_name).to eq('a')
13
+ expect(@session.find_by_id(:red).tag_name).to eq('a')
13
14
  end
14
15
 
15
16
  it "should raise error if no element with id is found" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find_field' do
3
4
  before do
4
5
  @session.visit('/form')
@@ -6,7 +7,7 @@ Capybara::SpecHelper.spec '#find_field' do
6
7
 
7
8
  it "should find any field" do
8
9
  expect(@session.find_field('Dog').value).to eq('dog')
9
- expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
10
+ expect(@session.find_field('form_description').value).to eq('Descriptive text goes here')
10
11
  expect(@session.find_field('Region')[:name]).to eq('form[region]')
11
12
  expect(@session.find_field('With Asterisk*')).to be
12
13
  end
@@ -26,7 +27,7 @@ Capybara::SpecHelper.spec '#find_field' do
26
27
  end
27
28
 
28
29
  it "casts to string" do
29
- expect(@session.find_field(:'Dog').value).to eq('dog')
30
+ expect(@session.find_field(:Dog).value).to eq('dog')
30
31
  end
31
32
 
32
33
  it "should raise error if the field doesn't exist" do
@@ -35,27 +36,20 @@ Capybara::SpecHelper.spec '#find_field' do
35
36
  end.to raise_error(Capybara::ElementNotFound)
36
37
  end
37
38
 
38
- it "should warn if filter option is invalid" do
39
- expect_any_instance_of(Kernel).to receive(:warn).
40
- with('Invalid value nil passed to filter disabled - defaulting to false')
41
- @session.find_field('Dog', disabled: nil)
42
- end
43
-
44
- it "should be aliased as 'field_labeled' for webrat compatibility" do
45
- expect(@session.field_labeled('Dog').value).to eq('dog')
39
+ it "should raise error if filter option is invalid" do
46
40
  expect do
47
- @session.field_labeled('Does not exist')
48
- end.to raise_error(Capybara::ElementNotFound)
41
+ @session.find_field('Dog', disabled: nil)
42
+ end.to raise_error ArgumentError, "Invalid value nil passed to filter disabled"
49
43
  end
50
44
 
51
45
  context "with :exact option" do
52
46
  it "should accept partial matches when false" do
53
- expect(@session.find_field("Explanation", exact: false)[:name]).to eq("form[name_explanation]")
47
+ expect(@session.find_field("Explanation", exact: false)[:name]).to eq("form[name_explanation]")
54
48
  end
55
49
 
56
50
  it "should not accept partial matches when true" do
57
51
  expect do
58
- @session.find_field("Explanation", exact: true)
52
+ @session.find_field("Explanation", exact: true)
59
53
  end.to raise_error(Capybara::ElementNotFound)
60
54
  end
61
55
  end
@@ -112,6 +106,6 @@ Capybara::SpecHelper.spec '#find_field' do
112
106
 
113
107
  it "should accept an optional filter block" do
114
108
  # this would be better done with the :with option but this is just a test
115
- expect(@session.find_field('form[pets][]'){ |node| node.value == 'dog' }[:id]).to eq "form_pets_dog"
109
+ expect(@session.find_field('form[pets][]') { |node| node.value == 'dog' }[:id]).to eq "form_pets_dog"
116
110
  end
117
111
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find_link' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -6,13 +7,13 @@ Capybara::SpecHelper.spec '#find_link' do
6
7
 
7
8
  it "should find any link" do
8
9
  expect(@session.find_link('foo').text).to eq("ullamco")
9
- expect(@session.find_link('labore')[:href]).to match %r(/with_simple_html$)
10
+ expect(@session.find_link('labore')[:href]).to match %r{/with_simple_html$}
10
11
  end
11
12
 
12
13
  context "aria_label attribute with Capybara.enable_aria_label" do
13
14
  it "should find when true" do
14
15
  Capybara.enable_aria_label = true
15
- expect(@session.find_link('Go to simple')[:href]).to match %r(/with_simple_html$)
16
+ expect(@session.find_link('Go to simple')[:href]).to match %r{/with_simple_html$}
16
17
  end
17
18
 
18
19
  it "should not find when false" do
@@ -22,7 +23,7 @@ Capybara::SpecHelper.spec '#find_link' do
22
23
  end
23
24
 
24
25
  it "casts to string" do
25
- expect(@session.find_link(:'foo').text).to eq("ullamco")
26
+ expect(@session.find_link(:foo).text).to eq("ullamco")
26
27
  end
27
28
 
28
29
  it "should raise error if the field doesn't exist" do
@@ -33,12 +34,12 @@ Capybara::SpecHelper.spec '#find_link' do
33
34
 
34
35
  context "with :exact option" do
35
36
  it "should accept partial matches when false" do
36
- expect(@session.find_link('abo', exact: false).text).to eq("labore")
37
+ expect(@session.find_link('abo', exact: false).text).to eq("labore")
37
38
  end
38
39
 
39
40
  it "should not accept partial matches when true" do
40
41
  expect do
41
- @session.find_link('abo', exact: true)
42
+ @session.find_link('abo', exact: true)
42
43
  end.to raise_error(Capybara::ElementNotFound)
43
44
  end
44
45
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#find' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -85,6 +86,11 @@ Capybara::SpecHelper.spec '#find' do
85
86
  it "should support pseudo selectors" do
86
87
  expect(@session.find(:css, 'input:disabled').value).to eq('This is disabled')
87
88
  end
89
+
90
+ it "should support escaping characters" do
91
+ expect(@session.find(:css, '#\31 escape\.me').text).to eq('needs escaping')
92
+ expect(@session.find(:css, '.\32 escape').text).to eq('needs escaping')
93
+ end
88
94
  end
89
95
 
90
96
  context "with xpath selectors" do
@@ -179,17 +185,17 @@ Capybara::SpecHelper.spec '#find' do
179
185
 
180
186
  it "should allow use of filters from custom filter set" do
181
187
  expect(@session.find(:id, 'test_field', filter_set: :value, with: 'monkey').value).to eq('monkey')
182
- expect{ @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
188
+ expect { @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
183
189
  end
184
190
 
185
191
  it "should allow use of filter set from a different selector" do
186
192
  expect(@session.find(:id, 'test_field', filter_set: :field, with: 'monkey').value).to eq('monkey')
187
- expect{ @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
193
+ expect { @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
188
194
  end
189
195
 
190
196
  it "should allow importing of filter set into selector" do
191
197
  expect(@session.find(:id_with_field_filters, 'test_field', with: 'monkey').value).to eq('monkey')
192
- expect{ @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
198
+ expect { @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
193
199
  end
194
200
  end
195
201
 
@@ -217,15 +223,15 @@ Capybara::SpecHelper.spec '#find' do
217
223
 
218
224
  context "with :exact option" do
219
225
  it "matches exactly when true" do
220
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
226
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
221
227
  expect do
222
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
228
+ @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
223
229
  end.to raise_error(Capybara::ElementNotFound)
224
230
  end
225
231
 
226
232
  it "matches loosely when false" do
227
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
228
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
233
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
234
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
229
235
  end
230
236
 
231
237
  it "defaults to `Capybara.exact`" do
@@ -238,8 +244,8 @@ Capybara::SpecHelper.spec '#find' do
238
244
  end
239
245
 
240
246
  it "warns when the option has no effect" do
241
- expect_any_instance_of(Kernel).to receive(:warn).
242
- with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
247
+ expect_any_instance_of(Kernel).to receive(:warn)
248
+ .with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
243
249
  @session.find(:css, '#test_field', exact: true)
244
250
  end
245
251
  end
@@ -253,7 +259,7 @@ Capybara::SpecHelper.spec '#find' do
253
259
  end
254
260
  it "raises an error even if there the match is exact and the others are inexact" do
255
261
  expect do
256
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
262
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
257
263
  end.to raise_error(Capybara::Ambiguous)
258
264
  end
259
265
  it "returns the element if there is only one" do
@@ -281,25 +287,25 @@ Capybara::SpecHelper.spec '#find' do
281
287
  context "and `exact` set to `false`" do
282
288
  it "raises an error when there are multiple exact matches" do
283
289
  expect do
284
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
290
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
285
291
  end.to raise_error(Capybara::Ambiguous)
286
292
  end
287
293
  it "finds a single exact match when there also are inexact matches" do
288
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
294
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
289
295
  expect(result.text).to eq("almost singular")
290
296
  end
291
297
  it "raises an error when there are multiple inexact matches" do
292
298
  expect do
293
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
299
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
294
300
  end.to raise_error(Capybara::Ambiguous)
295
301
  end
296
302
  it "finds a single inexact match" do
297
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
303
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
298
304
  expect(result.text).to eq("almost singular but not quite")
299
305
  end
300
306
  it "raises an error if there is no match" do
301
307
  expect do
302
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
308
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
303
309
  end.to raise_error(Capybara::ElementNotFound)
304
310
  end
305
311
  end
@@ -307,26 +313,26 @@ Capybara::SpecHelper.spec '#find' do
307
313
  context "with `exact` set to `true`" do
308
314
  it "raises an error when there are multiple exact matches" do
309
315
  expect do
310
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
316
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
311
317
  end.to raise_error(Capybara::Ambiguous)
312
318
  end
313
319
  it "finds a single exact match when there also are inexact matches" do
314
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
320
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
315
321
  expect(result.text).to eq("almost singular")
316
322
  end
317
323
  it "raises an error when there are multiple inexact matches" do
318
324
  expect do
319
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
325
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
320
326
  end.to raise_error(Capybara::ElementNotFound)
321
327
  end
322
328
  it "raises an error when there is a single inexact matches" do
323
329
  expect do
324
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
330
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
325
331
  end.to raise_error(Capybara::ElementNotFound)
326
332
  end
327
333
  it "raises an error if there is no match" do
328
334
  expect do
329
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
335
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
330
336
  end.to raise_error(Capybara::ElementNotFound)
331
337
  end
332
338
  end
@@ -335,50 +341,50 @@ Capybara::SpecHelper.spec '#find' do
335
341
  context "when set to `prefer_exact`" do
336
342
  context "and `exact` set to `false`" do
337
343
  it "picks the first one when there are multiple exact matches" do
338
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
344
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
339
345
  expect(result.text).to eq("multiple one")
340
346
  end
341
347
  it "finds a single exact match when there also are inexact matches" do
342
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
348
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
343
349
  expect(result.text).to eq("almost singular")
344
350
  end
345
351
  it "picks the first one when there are multiple inexact matches" do
346
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
352
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
347
353
  expect(result.text).to eq("almost singular but not quite")
348
354
  end
349
355
  it "finds a single inexact match" do
350
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
356
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
351
357
  expect(result.text).to eq("almost singular but not quite")
352
358
  end
353
359
  it "raises an error if there is no match" do
354
360
  expect do
355
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
361
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
356
362
  end.to raise_error(Capybara::ElementNotFound)
357
363
  end
358
364
  end
359
365
 
360
366
  context "with `exact` set to `true`" do
361
367
  it "picks the first one when there are multiple exact matches" do
362
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
368
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
363
369
  expect(result.text).to eq("multiple one")
364
370
  end
365
371
  it "finds a single exact match when there also are inexact matches" do
366
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
372
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
367
373
  expect(result.text).to eq("almost singular")
368
374
  end
369
375
  it "raises an error if there are multiple inexact matches" do
370
376
  expect do
371
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
377
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
372
378
  end.to raise_error(Capybara::ElementNotFound)
373
379
  end
374
380
  it "raises an error if there is a single inexact match" do
375
381
  expect do
376
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
382
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
377
383
  end.to raise_error(Capybara::ElementNotFound)
378
384
  end
379
385
  it "raises an error if there is no match" do
380
386
  expect do
381
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
387
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
382
388
  end.to raise_error(Capybara::ElementNotFound)
383
389
  end
384
390
  end
@@ -401,7 +407,7 @@ Capybara::SpecHelper.spec '#find' do
401
407
  end
402
408
 
403
409
  it "supports a custom filter block" do
404
- expect(@session.find(:css, 'input'){|node| node.disabled? }[:name]).to eq('disabled_text')
410
+ expect(@session.find(:css, 'input', &:disabled?)[:name]).to eq('disabled_text')
405
411
  end
406
412
 
407
413
  context "within a scope" do