capybara 2.6.0 → 2.7.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 (163) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +52 -15
  3. data/README.md +45 -38
  4. data/lib/capybara/cucumber.rb +1 -0
  5. data/lib/capybara/driver/base.rb +5 -2
  6. data/lib/capybara/driver/node.rb +1 -0
  7. data/lib/capybara/dsl.rb +1 -0
  8. data/lib/capybara/helpers.rb +3 -2
  9. data/lib/capybara/node/actions.rb +6 -0
  10. data/lib/capybara/node/base.rb +1 -0
  11. data/lib/capybara/node/document.rb +1 -0
  12. data/lib/capybara/node/document_matchers.rb +1 -0
  13. data/lib/capybara/node/element.rb +1 -0
  14. data/lib/capybara/node/finders.rb +3 -2
  15. data/lib/capybara/node/matchers.rb +72 -2
  16. data/lib/capybara/node/simple.rb +6 -3
  17. data/lib/capybara/queries/base_query.rb +1 -0
  18. data/lib/capybara/queries/current_path_query.rb +6 -3
  19. data/lib/capybara/queries/match_query.rb +21 -0
  20. data/lib/capybara/queries/selector_query.rb +138 -0
  21. data/lib/capybara/queries/text_query.rb +1 -0
  22. data/lib/capybara/queries/title_query.rb +1 -0
  23. data/lib/capybara/query.rb +3 -131
  24. data/lib/capybara/rack_test/browser.rb +1 -0
  25. data/lib/capybara/rack_test/css_handlers.rb +1 -0
  26. data/lib/capybara/rack_test/driver.rb +6 -4
  27. data/lib/capybara/rack_test/form.rb +1 -0
  28. data/lib/capybara/rack_test/node.rb +1 -0
  29. data/lib/capybara/rails.rb +2 -1
  30. data/lib/capybara/result.rb +1 -0
  31. data/lib/capybara/rspec/features.rb +1 -0
  32. data/lib/capybara/rspec/matchers.rb +54 -3
  33. data/lib/capybara/rspec.rb +1 -0
  34. data/lib/capybara/selector/filter.rb +48 -0
  35. data/lib/capybara/selector.rb +175 -75
  36. data/lib/capybara/selenium/driver.rb +24 -7
  37. data/lib/capybara/selenium/node.rb +1 -0
  38. data/lib/capybara/server.rb +38 -6
  39. data/lib/capybara/session/matchers.rb +2 -1
  40. data/lib/capybara/session.rb +30 -14
  41. data/lib/capybara/spec/public/test.js +6 -0
  42. data/lib/capybara/spec/session/accept_alert_spec.rb +2 -1
  43. data/lib/capybara/spec/session/accept_confirm_spec.rb +2 -1
  44. data/lib/capybara/spec/session/accept_prompt_spec.rb +2 -1
  45. data/lib/capybara/spec/session/all_spec.rb +1 -0
  46. data/lib/capybara/spec/session/assert_current_path.rb +1 -0
  47. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  48. data/lib/capybara/spec/session/assert_text.rb +1 -0
  49. data/lib/capybara/spec/session/assert_title.rb +1 -0
  50. data/lib/capybara/spec/session/attach_file_spec.rb +1 -0
  51. data/lib/capybara/spec/session/body_spec.rb +1 -0
  52. data/lib/capybara/spec/session/check_spec.rb +1 -0
  53. data/lib/capybara/spec/session/choose_spec.rb +1 -0
  54. data/lib/capybara/spec/session/click_button_spec.rb +1 -0
  55. data/lib/capybara/spec/session/click_link_or_button_spec.rb +1 -0
  56. data/lib/capybara/spec/session/click_link_spec.rb +1 -0
  57. data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
  58. data/lib/capybara/spec/session/current_url_spec.rb +1 -0
  59. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +2 -1
  60. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -1
  61. data/lib/capybara/spec/session/element/assert_match_selector.rb +31 -0
  62. data/lib/capybara/spec/session/element/match_css_spec.rb +17 -0
  63. data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
  64. data/lib/capybara/spec/session/element/matches_selector_spec.rb +63 -0
  65. data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -0
  66. data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
  67. data/lib/capybara/spec/session/fill_in_spec.rb +1 -0
  68. data/lib/capybara/spec/session/find_button_spec.rb +1 -0
  69. data/lib/capybara/spec/session/find_by_id_spec.rb +1 -0
  70. data/lib/capybara/spec/session/find_field_spec.rb +1 -0
  71. data/lib/capybara/spec/session/find_link_spec.rb +1 -0
  72. data/lib/capybara/spec/session/find_spec.rb +1 -0
  73. data/lib/capybara/spec/session/first_spec.rb +1 -0
  74. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  75. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  76. data/lib/capybara/spec/session/has_button_spec.rb +1 -0
  77. data/lib/capybara/spec/session/has_css_spec.rb +1 -0
  78. data/lib/capybara/spec/session/has_current_path_spec.rb +1 -0
  79. data/lib/capybara/spec/session/has_field_spec.rb +13 -0
  80. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  81. data/lib/capybara/spec/session/has_select_spec.rb +19 -0
  82. data/lib/capybara/spec/session/has_selector_spec.rb +6 -0
  83. data/lib/capybara/spec/session/has_table_spec.rb +1 -0
  84. data/lib/capybara/spec/session/has_text_spec.rb +1 -0
  85. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  86. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  87. data/lib/capybara/spec/session/headers.rb +1 -0
  88. data/lib/capybara/spec/session/html_spec.rb +1 -0
  89. data/lib/capybara/spec/session/node_spec.rb +29 -0
  90. data/lib/capybara/spec/session/reset_session_spec.rb +35 -1
  91. data/lib/capybara/spec/session/response_code.rb +1 -0
  92. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  93. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -2
  94. data/lib/capybara/spec/session/save_page_spec.rb +34 -2
  95. data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
  96. data/lib/capybara/spec/session/screenshot_spec.rb +3 -1
  97. data/lib/capybara/spec/session/select_spec.rb +1 -0
  98. data/lib/capybara/spec/session/selectors_spec.rb +35 -0
  99. data/lib/capybara/spec/session/text_spec.rb +1 -0
  100. data/lib/capybara/spec/session/title_spec.rb +2 -1
  101. data/lib/capybara/spec/session/uncheck_spec.rb +1 -0
  102. data/lib/capybara/spec/session/unselect_spec.rb +1 -0
  103. data/lib/capybara/spec/session/visit_spec.rb +1 -0
  104. data/lib/capybara/spec/session/window/become_closed_spec.rb +1 -0
  105. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  106. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  107. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -0
  108. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -0
  109. data/lib/capybara/spec/session/window/window_spec.rb +1 -8
  110. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  111. data/lib/capybara/spec/session/window/within_window_spec.rb +2 -3
  112. data/lib/capybara/spec/session/within_frame_spec.rb +1 -0
  113. data/lib/capybara/spec/session/within_spec.rb +1 -0
  114. data/lib/capybara/spec/spec_helper.rb +2 -0
  115. data/lib/capybara/spec/test_app.rb +1 -0
  116. data/lib/capybara/spec/views/buttons.erb +1 -0
  117. data/lib/capybara/spec/views/fieldsets.erb +2 -1
  118. data/lib/capybara/spec/views/form.erb +24 -0
  119. data/lib/capybara/spec/views/frame_child.erb +2 -1
  120. data/lib/capybara/spec/views/frame_one.erb +2 -1
  121. data/lib/capybara/spec/views/frame_parent.erb +2 -1
  122. data/lib/capybara/spec/views/frame_two.erb +2 -1
  123. data/lib/capybara/spec/views/header_links.erb +1 -0
  124. data/lib/capybara/spec/views/host_links.erb +1 -0
  125. data/lib/capybara/spec/views/path.erb +1 -0
  126. data/lib/capybara/spec/views/popup_one.erb +1 -0
  127. data/lib/capybara/spec/views/popup_two.erb +1 -0
  128. data/lib/capybara/spec/views/postback.erb +2 -1
  129. data/lib/capybara/spec/views/tables.erb +1 -0
  130. data/lib/capybara/spec/views/with_base_tag.erb +1 -0
  131. data/lib/capybara/spec/views/with_count.erb +2 -1
  132. data/lib/capybara/spec/views/with_hover.erb +2 -1
  133. data/lib/capybara/spec/views/with_html.erb +3 -0
  134. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  135. data/lib/capybara/spec/views/with_js.erb +5 -0
  136. data/lib/capybara/spec/views/with_scope.erb +1 -0
  137. data/lib/capybara/spec/views/with_simple_html.erb +2 -1
  138. data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
  139. data/lib/capybara/spec/views/with_title.erb +2 -1
  140. data/lib/capybara/spec/views/with_unload_alert.erb +12 -0
  141. data/lib/capybara/spec/views/with_windows.erb +1 -0
  142. data/lib/capybara/spec/views/within_frames.erb +2 -1
  143. data/lib/capybara/version.rb +2 -1
  144. data/lib/capybara/window.rb +1 -0
  145. data/lib/capybara.rb +86 -10
  146. data/spec/basic_node_spec.rb +1 -0
  147. data/spec/capybara_spec.rb +28 -1
  148. data/spec/dsl_spec.rb +1 -0
  149. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -0
  150. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -0
  151. data/spec/rack_test_spec.rb +1 -0
  152. data/spec/result_spec.rb +1 -0
  153. data/spec/rspec/features_spec.rb +1 -0
  154. data/spec/rspec/matchers_spec.rb +1 -0
  155. data/spec/rspec/scenarios_spec.rb +1 -0
  156. data/spec/rspec/views_spec.rb +1 -0
  157. data/spec/rspec_spec.rb +1 -0
  158. data/spec/selector_spec.rb +55 -1
  159. data/spec/selenium_spec.rb +6 -2
  160. data/spec/selenium_spec_chrome.rb +1 -0
  161. data/spec/server_spec.rb +101 -13
  162. data/spec/spec_helper.rb +1 -0
  163. metadata +16 -6
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'capybara/session/matchers'
2
3
 
3
4
  module Capybara
@@ -106,9 +107,9 @@ module Capybara
106
107
  def reset!
107
108
  if @touched
108
109
  driver.reset!
109
- assert_no_selector :xpath, "/html/body/*" if driver.browser_initialized?
110
110
  @touched = false
111
111
  end
112
+ @server.wait_for_pending_requests if @server
112
113
  raise_server_error!
113
114
  end
114
115
  alias_method :cleanup!, :reset!
@@ -402,7 +403,7 @@ module Capybara
402
403
  driver.switch_to_window(window.handle)
403
404
  window
404
405
  else
405
- wait_time = Capybara::Query.new(options).wait
406
+ wait_time = Capybara::Queries::SelectorQuery.new(options).wait
406
407
  document.synchronize(wait_time, errors: [Capybara::WindowError]) do
407
408
  original_window_handle = driver.current_window_handle
408
409
  begin
@@ -499,7 +500,7 @@ module Capybara
499
500
  old_handles = driver.window_handles
500
501
  block.call
501
502
 
502
- wait_time = Capybara::Query.new(options).wait
503
+ wait_time = Capybara::Queries::SelectorQuery.new(options).wait
503
504
  document.synchronize(wait_time, errors: [Capybara::WindowError]) do
504
505
  opened_handles = (driver.window_handles - old_handles)
505
506
  if opened_handles.size != 1
@@ -619,8 +620,11 @@ module Capybara
619
620
  # Save a snapshot of the page. If `Capybara.asset_host` is set it will inject `base` tag
620
621
  # pointing to `asset_host`.
621
622
  #
622
- # If invoked without arguments it will save file to `Capybara.save_and_open_page_path`
623
- # and file will be given randomly generated filename.
623
+ # If invoked without arguments it will save file to `Capybara.save_path`
624
+ # and file will be given randomly generated filename. If invoked with a relative path
625
+ # the path will be relative to `Capybara.save_path`, which is different from
626
+ # the previous behavior with `Capybara.save_and_open_page_path` where the relative path was
627
+ # relative to Dir.pwd
624
628
  #
625
629
  # @param [String] path the path to where it should be saved
626
630
  # @return [String] the path to which the file was saved
@@ -635,8 +639,11 @@ module Capybara
635
639
  #
636
640
  # Save a snapshot of the page and open it in a browser for inspection.
637
641
  #
638
- # If invoked without arguments it will save file to `Capybara.save_and_open_page_path`
639
- # and file will be given randomly generated filename.
642
+ # If invoked without arguments it will save file to `Capybara.save_path`
643
+ # and file will be given randomly generated filename. If invoked with a relative path
644
+ # the path will be relative to `Capybara.save_path`, which is different from
645
+ # the previous behavior with `Capybara.save_and_open_page_path` where the relative path was
646
+ # relative to Dir.pwd
640
647
  #
641
648
  # @param [String] path the path to where it should be saved
642
649
  #
@@ -649,8 +656,11 @@ module Capybara
649
656
  #
650
657
  # Save a screenshot of page.
651
658
  #
652
- # If invoked without `path` argument it will save file to `Capybara.save_and_open_page_path`
653
- # and file will be given randomly generated filename.
659
+ # If invoked without arguments it will save file to `Capybara.save_path`
660
+ # and file will be given randomly generated filename. If invoked with a relative path
661
+ # the path will be relative to `Capybara.save_path`, which is different from
662
+ # the previous behavior with `Capybara.save_and_open_page_path` where the relative path was
663
+ # relative to Dir.pwd
654
664
  #
655
665
  # @param [String] path the path to where it should be saved
656
666
  # @param [Hash] options a customizable set of options
@@ -665,8 +675,11 @@ module Capybara
665
675
  #
666
676
  # Save a screenshot of the page and open it for inspection.
667
677
  #
668
- # If invoked without `path` argument it will save file to `Capybara.save_and_open_page_path`
669
- # and file will be given randomly generated filename.
678
+ # If invoked without arguments it will save file to `Capybara.save_path`
679
+ # and file will be given randomly generated filename. If invoked with a relative path
680
+ # the path will be relative to `Capybara.save_path`, which is different from
681
+ # the previous behavior with `Capybara.save_and_open_page_path` where the relative path was
682
+ # relative to Dir.pwd
670
683
  #
671
684
  # @param [String] path the path to where it should be saved
672
685
  # @param [Hash] options a customizable set of options
@@ -714,15 +727,18 @@ module Capybara
714
727
  end
715
728
 
716
729
  def prepare_path(path, extension)
717
- path = default_path(extension) if path.nil?
730
+ if Capybara.save_path || Capybara.save_and_open_page_path.nil?
731
+ path = File.expand_path(path || default_fn(extension), Capybara.save_path)
732
+ else
733
+ path = File.expand_path(default_fn(extension), Capybara.save_and_open_page_path) if path.nil?
734
+ end
718
735
  FileUtils.mkdir_p(File.dirname(path))
719
736
  path
720
737
  end
721
738
 
722
- def default_path(extension)
739
+ def default_fn(extension)
723
740
  timestamp = Time.new.strftime("%Y%m%d%H%M%S")
724
741
  path = "capybara-#{timestamp}#{rand(10**10)}.#{extension}"
725
- File.expand_path(path, Capybara.save_and_open_page_path)
726
742
  end
727
743
 
728
744
  def scopes
@@ -117,4 +117,10 @@ $(function() {
117
117
  $('#with-key-events').keydown(function(e){
118
118
  $('#key-events-output').append('keydown:'+e.which+' ')
119
119
  });
120
+ $('#disable-on-click').click(function(e){
121
+ var input = this
122
+ setTimeout(function() {
123
+ input.disabled = true;
124
+ }, 500)
125
+ })
120
126
  });
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -54,4 +55,4 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
54
55
  expect(@session).to have_xpath("//a[@id='open-slow-alert' and @opened='true']")
55
56
  end
56
57
  end
57
- end
58
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#accept_confirm', :requires => [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -27,4 +28,4 @@ Capybara::SpecHelper.spec '#accept_confirm', :requires => [:modals] do
27
28
  }.not_to raise_error
28
29
  expect(@session).to have_xpath("//a[@id='open-twice' and @confirmed='false']")
29
30
  end
30
- end
31
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -46,4 +47,4 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
46
47
  end
47
48
  expect(message).to eq('Prompt opened')
48
49
  end
49
- end
50
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#all" do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_current_path' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_selector' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_text' do
2
3
  it "should be true if the given text is on the page" do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_title' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#attach_file" do
2
3
  before do
3
4
  @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#body' do
2
3
  it "should return the unmodified page body" do
3
4
  @session.visit('/')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#check" do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#choose" do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#click_button' do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#click_link_or_button' do
2
3
  it "should click on a link" do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#click_link' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#current_scope' do
2
3
  before do
3
4
  @session.visit('/with_scope')
@@ -26,4 +27,4 @@ Capybara::SpecHelper.spec '#current_scope' do
26
27
  end
27
28
  end
28
29
  end
29
- end
30
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "capybara/spec/test_app"
2
3
 
3
4
  Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#dismiss_confirm', :requires => [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -32,4 +33,4 @@ Capybara::SpecHelper.spec '#dismiss_confirm', :requires => [:modals] do
32
33
  end
33
34
  expect(message).to eq('Confirm opened')
34
35
  end
35
- end
36
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#dismiss_prompt', :requires => [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -16,4 +17,4 @@ Capybara::SpecHelper.spec '#dismiss_prompt', :requires => [:modals] do
16
17
  end
17
18
  expect(message).to eq('Prompt opened')
18
19
  end
19
- end
20
+ end
@@ -0,0 +1,31 @@
1
+ Capybara::SpecHelper.spec '#assert_matches_selector' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ @element = @session.find(:css, 'span', text: '42')
5
+ end
6
+
7
+ it "should be true if the given selector matches the element" do
8
+ expect(@element.assert_matches_selector(:css, '.number')).to be true
9
+ end
10
+
11
+ it "should be false if the given selector does not match the element" do
12
+ expect { @element.assert_matches_selector(:css, '.not_number') }.to raise_error(Capybara::ElementNotFound)
13
+ end
14
+
15
+ it "should not be callable on the session" do
16
+ expect { @session.assert_matches_selector(:css, '.number') }.to raise_error(NoMethodError)
17
+ end
18
+
19
+ it "should wait for match to occur", requires: [:js] do
20
+ @session.visit('/with_js')
21
+ input = @session.find(:css, '#disable-on-click')
22
+
23
+ expect(input.assert_matches_selector(:css, 'input:enabled')).to be true
24
+ input.click
25
+ expect(input.assert_matches_selector(:css, 'input:disabled')).to be true
26
+ end
27
+
28
+ it "should not accept count options" do
29
+ expect { @element.assert_matches_selector(:css, '.number', count: 1) }.to raise_error(ArgumentError)
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ Capybara::SpecHelper.spec '#match_css?' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ @element = @session.find(:css, 'span', text: '42')
5
+ end
6
+
7
+ it "should be true if the given selector matches the element" do
8
+ expect(@element).to match_css("span")
9
+ expect(@element).to match_css("span.number")
10
+ end
11
+
12
+ it "should be false if the given selector does not match" do
13
+ expect(@element).not_to match_css("div")
14
+ expect(@element).not_to match_css("p a#doesnotexist")
15
+ expect(@element).not_to match_css("p.nosuchclass")
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ Capybara::SpecHelper.spec '#match_xpath?' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ @element = @session.find(:css, 'span.number')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ expect(@element).to match_xpath("//span")
9
+ expect(@element).to match_xpath("//span[@class='number']")
10
+ end
11
+
12
+ it "should be false if the given selector is not on the page" do
13
+ expect(@element).not_to match_xpath("//abbr")
14
+ expect(@element).not_to match_xpath("//div")
15
+ expect(@element).not_to match_xpath("//span[@class='not_a_number']")
16
+ end
17
+
18
+ it "should use xpath even if default selector is CSS" do
19
+ Capybara.default_selector = :css
20
+ expect(@element).not_to have_xpath("//span[@class='not_a_number']")
21
+ expect(@element).not_to have_xpath("//div[@class='number']")
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ Capybara::SpecHelper.spec '#match_xpath?' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ @element = @session.find('//span', text: '42')
5
+ end
6
+
7
+ it "should be true if the element matches the given selector" do
8
+ expect(@element).to match_selector(:xpath, "//span")
9
+ expect(@element).to match_selector(:css, 'span.number')
10
+ expect(@element.matches_selector?(:css, 'span.number')).to be true
11
+ end
12
+
13
+ it "should be false if the element does not match the given selector" do
14
+ expect(@element).not_to match_selector(:xpath, "//div")
15
+ expect(@element).not_to match_selector(:css, "span.not_a_number")
16
+ expect(@element.matches_selector?(:css, "span.not_a_number")).to be false
17
+ end
18
+
19
+ it "should use default selector" do
20
+ Capybara.default_selector = :css
21
+ expect(@element).not_to match_selector("span.not_a_number")
22
+ expect(@element).to match_selector("span.number")
23
+ end
24
+
25
+ context "with text" do
26
+ it "should discard all matches where the given string is not contained" do
27
+ expect(@element).to match_selector("//span", :text => "42")
28
+ expect(@element).not_to match_selector("//span", :text => "Doesnotexist")
29
+ end
30
+ end
31
+ end
32
+
33
+ Capybara::SpecHelper.spec '#not_matches_selector?' do
34
+ before do
35
+ @session.visit('/with_html')
36
+ @element = @session.find(:css, "span", text: 42)
37
+ end
38
+
39
+ it "should be false if the given selector matches the element" do
40
+ expect(@element).not_to not_match_selector(:xpath, "//span")
41
+ expect(@element).not_to not_match_selector(:css, "span.number")
42
+ expect(@element.not_matches_selector?(:css, "span.number")).to be false
43
+ end
44
+
45
+ it "should be true if the given selector does not match the element" do
46
+ expect(@element).to not_match_selector(:xpath, "//abbr")
47
+ expect(@element).to not_match_selector(:css, "p a#doesnotexist")
48
+ expect(@element.not_matches_selector?(:css, "p a#doesnotexist")).to be true
49
+ end
50
+
51
+ it "should use default selector" do
52
+ Capybara.default_selector = :css
53
+ expect(@element).to not_match_selector("p a#doesnotexist")
54
+ expect(@element).not_to not_match_selector("span.number")
55
+ end
56
+
57
+ context "with text" do
58
+ it "should discard all matches where the given string is contained" do
59
+ expect(@element).not_to not_match_selector(:css, "span.number", :text => "42")
60
+ expect(@element).to not_match_selector(:css, "span.number", :text => "Doesnotexist")
61
+ end
62
+ end
63
+ end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#evaluate_script", :requires => [:js] do
2
3
  it "should evaluate the given script and return whatever it produces" do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#execute_script", :requires => [:js] do
2
3
  it "should execute the given script and return nothing" do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#fill_in" do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#find_button' do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#find_by_id' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#find_field' do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#find_link' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#find' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#first' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#go_back', :requires => [:js] do
2
3
  it "should fetch a response from the driver from the previous page" do
3
4
  @session.visit('/')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#go_forward', :requires => [:js] do
2
3
  it "should fetch a response from the driver from the previous page" do
3
4
  @session.visit('/')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_button?' do
2
3
  before do
3
4
  @session.visit('/form')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_css?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_current_path?' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_field' do
2
3
  before { @session.visit('/form') }
3
4
 
@@ -41,6 +42,7 @@ Capybara::SpecHelper.spec '#has_field' do
41
42
  it "should be true if a field with the given type is on the page" do
42
43
  expect(@session).to have_field('First Name', :type => 'text')
43
44
  expect(@session).to have_field('Html5 Email', :type => 'email')
45
+ expect(@session).to have_field('Html5 Multiple Email', :type => 'email')
44
46
  expect(@session).to have_field('Html5 Tel', :type => 'tel')
45
47
  expect(@session).to have_field('Description', :type => 'textarea')
46
48
  expect(@session).to have_field('Languages', :type => 'select')
@@ -49,11 +51,22 @@ Capybara::SpecHelper.spec '#has_field' do
49
51
  it "should be false if the given field is not on the page" do
50
52
  expect(@session).not_to have_field('First Name', :type => 'textarea')
51
53
  expect(@session).not_to have_field('Html5 Email', :type => 'tel')
54
+ expect(@session).not_to have_field('Html5 Multiple Email', :type => 'tel')
52
55
  expect(@session).not_to have_field('Description', :type => '')
53
56
  expect(@session).not_to have_field('Description', :type => 'email')
54
57
  expect(@session).not_to have_field('Languages', :type => 'textarea')
55
58
  end
56
59
  end
60
+
61
+ context 'with multiple' do
62
+ it "should be true if a field with the multiple attribute is on the page" do
63
+ expect(@session).to have_field('Html5 Multiple Email', multiple: true)
64
+ end
65
+
66
+ it "should be false if a field without the multiple attribute is not on the page" do
67
+ expect(@session).not_to have_field('Html5 Multiple Email', multiple: false)
68
+ end
69
+ end
57
70
  end
58
71
 
59
72
  Capybara::SpecHelper.spec '#has_no_field' do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_link?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_select?' do
2
3
  before { @session.visit('/form') }
3
4
 
@@ -102,6 +103,24 @@ Capybara::SpecHelper.spec '#has_select?' do
102
103
  expect(@session).to have_select("Icecream", :visible => false, :with_options => ['Vanilla', 'Strawberry'])
103
104
  end
104
105
  end
106
+
107
+ context 'with multiple option' do
108
+ it "should find multiple selects if true" do
109
+ expect(@session).to have_select('form_languages', multiple: true)
110
+ expect(@session).not_to have_select('form_other_title', multiple: true)
111
+ end
112
+
113
+ it "should not find multiple selects if false" do
114
+ expect(@session).not_to have_select('form_languages', multiple: false)
115
+ expect(@session).to have_select('form_other_title', multiple: false)
116
+ end
117
+
118
+ it "should find both if not specified" do
119
+ expect(@session).to have_select('form_languages')
120
+ expect(@session).to have_select('form_other_title')
121
+ end
122
+ end
123
+
105
124
  end
106
125
 
107
126
  Capybara::SpecHelper.spec '#has_no_select?' do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_selector?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -66,6 +67,11 @@ Capybara::SpecHelper.spec '#has_selector?' do
66
67
  expect(@session).to have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
67
68
  expect(@session).not_to have_selector("//p//a", :text => /Red$/)
68
69
  end
70
+
71
+ it "should warn when extra parameters passed" do
72
+ expect_any_instance_of(Kernel).to receive(:warn).with(/extra/)
73
+ expect(@session).to have_selector(:css, "p a#foo", 'extra')
74
+ end
69
75
  end
70
76
  end
71
77
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_table?' do
2
3
  before do
3
4
  @session.visit('/tables')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_text?' do
2
3
  it "should be true if the given text is on the page at least once" do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_title?' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#has_xpath?' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#response_headers' do
2
3
  it "should return response headers", :requires => [:response_headers] do
3
4
  @session.visit('/with_simple_html')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#html' do
2
3
  it "should return the unmodified page body" do
3
4
  @session.visit('/')