capybara 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +16 -0
  3. data/README.md +5 -7
  4. data/lib/capybara.rb +7 -6
  5. data/lib/capybara/config.rb +1 -1
  6. data/lib/capybara/dsl.rb +2 -2
  7. data/lib/capybara/helpers.rb +3 -3
  8. data/lib/capybara/minitest/spec.rb +3 -3
  9. data/lib/capybara/node/actions.rb +18 -18
  10. data/lib/capybara/node/base.rb +1 -1
  11. data/lib/capybara/node/element.rb +2 -2
  12. data/lib/capybara/node/finders.rb +6 -6
  13. data/lib/capybara/node/matchers.rb +5 -5
  14. data/lib/capybara/node/simple.rb +2 -2
  15. data/lib/capybara/queries/ancestor_query.rb +1 -1
  16. data/lib/capybara/queries/base_query.rb +12 -11
  17. data/lib/capybara/queries/current_path_query.rb +1 -1
  18. data/lib/capybara/queries/selector_query.rb +39 -15
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/text_query.rb +1 -1
  21. data/lib/capybara/rack_test/browser.rb +7 -7
  22. data/lib/capybara/rack_test/driver.rb +1 -1
  23. data/lib/capybara/rack_test/form.rb +7 -7
  24. data/lib/capybara/rack_test/node.rb +16 -16
  25. data/lib/capybara/rails.rb +1 -1
  26. data/lib/capybara/result.rb +8 -4
  27. data/lib/capybara/rspec/features.rb +4 -4
  28. data/lib/capybara/rspec/matchers.rb +6 -6
  29. data/lib/capybara/selector.rb +106 -90
  30. data/lib/capybara/selector/css.rb +4 -4
  31. data/lib/capybara/selector/filter_set.rb +52 -8
  32. data/lib/capybara/selector/selector.rb +39 -15
  33. data/lib/capybara/selenium/driver.rb +10 -10
  34. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -0
  35. data/lib/capybara/selenium/node.rb +9 -10
  36. data/lib/capybara/selenium/nodes/chrome_node.rb +18 -0
  37. data/lib/capybara/selenium/nodes/marionette_node.rb +32 -7
  38. data/lib/capybara/server.rb +3 -3
  39. data/lib/capybara/server/animation_disabler.rb +1 -1
  40. data/lib/capybara/server/middleware.rb +1 -1
  41. data/lib/capybara/session.rb +23 -19
  42. data/lib/capybara/session/config.rb +18 -3
  43. data/lib/capybara/spec/public/test.js +1 -1
  44. data/lib/capybara/spec/session/accept_alert_spec.rb +10 -10
  45. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
  46. data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
  47. data/lib/capybara/spec/session/all_spec.rb +33 -32
  48. data/lib/capybara/spec/session/ancestor_spec.rb +19 -19
  49. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +38 -38
  50. data/lib/capybara/spec/session/assert_current_path_spec.rb +16 -16
  51. data/lib/capybara/spec/session/assert_selector_spec.rb +53 -53
  52. data/lib/capybara/spec/session/assert_style_spec.rb +3 -3
  53. data/lib/capybara/spec/session/assert_text_spec.rb +31 -30
  54. data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
  55. data/lib/capybara/spec/session/attach_file_spec.rb +51 -52
  56. data/lib/capybara/spec/session/body_spec.rb +6 -6
  57. data/lib/capybara/spec/session/check_spec.rb +52 -47
  58. data/lib/capybara/spec/session/choose_spec.rb +32 -32
  59. data/lib/capybara/spec/session/click_button_spec.rb +103 -103
  60. data/lib/capybara/spec/session/click_link_or_button_spec.rb +24 -23
  61. data/lib/capybara/spec/session/click_link_spec.rb +49 -48
  62. data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
  63. data/lib/capybara/spec/session/current_url_spec.rb +26 -27
  64. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
  65. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
  66. data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
  67. data/lib/capybara/spec/session/element/match_css_spec.rb +10 -10
  68. data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
  69. data/lib/capybara/spec/session/element/matches_selector_spec.rb +51 -51
  70. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
  71. data/lib/capybara/spec/session/evaluate_script_spec.rb +15 -8
  72. data/lib/capybara/spec/session/execute_script_spec.rb +7 -7
  73. data/lib/capybara/spec/session/fill_in_spec.rb +43 -42
  74. data/lib/capybara/spec/session/find_button_spec.rb +23 -23
  75. data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
  76. data/lib/capybara/spec/session/find_field_spec.rb +32 -30
  77. data/lib/capybara/spec/session/find_link_spec.rb +21 -21
  78. data/lib/capybara/spec/session/find_spec.rb +153 -135
  79. data/lib/capybara/spec/session/first_spec.rb +41 -41
  80. data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
  81. data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
  82. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +17 -17
  83. data/lib/capybara/spec/session/frame/within_frame_spec.rb +31 -17
  84. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  85. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  86. data/lib/capybara/spec/session/has_all_selectors_spec.rb +17 -17
  87. data/lib/capybara/spec/session/has_button_spec.rb +13 -13
  88. data/lib/capybara/spec/session/has_css_spec.rb +133 -131
  89. data/lib/capybara/spec/session/has_current_path_spec.rb +29 -29
  90. data/lib/capybara/spec/session/has_field_spec.rb +58 -58
  91. data/lib/capybara/spec/session/has_link_spec.rb +4 -4
  92. data/lib/capybara/spec/session/has_none_selectors_spec.rb +24 -24
  93. data/lib/capybara/spec/session/has_select_spec.rb +43 -43
  94. data/lib/capybara/spec/session/has_selector_spec.rb +71 -71
  95. data/lib/capybara/spec/session/has_style_spec.rb +3 -3
  96. data/lib/capybara/spec/session/has_table_spec.rb +4 -4
  97. data/lib/capybara/spec/session/has_text_spec.rb +53 -52
  98. data/lib/capybara/spec/session/has_title_spec.rb +14 -14
  99. data/lib/capybara/spec/session/has_xpath_spec.rb +39 -38
  100. data/lib/capybara/spec/session/headers_spec.rb +1 -1
  101. data/lib/capybara/spec/session/html_spec.rb +6 -6
  102. data/lib/capybara/spec/session/node_spec.rb +129 -123
  103. data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
  104. data/lib/capybara/spec/session/refresh_spec.rb +4 -7
  105. data/lib/capybara/spec/session/reset_session_spec.rb +28 -28
  106. data/lib/capybara/spec/session/response_code_spec.rb +1 -1
  107. data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
  108. data/lib/capybara/spec/session/save_page_spec.rb +37 -37
  109. data/lib/capybara/spec/session/save_screenshot_spec.rb +6 -6
  110. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  111. data/lib/capybara/spec/session/select_spec.rb +81 -81
  112. data/lib/capybara/spec/session/selectors_spec.rb +17 -17
  113. data/lib/capybara/spec/session/sibling_spec.rb +9 -9
  114. data/lib/capybara/spec/session/text_spec.rb +23 -23
  115. data/lib/capybara/spec/session/title_spec.rb +5 -5
  116. data/lib/capybara/spec/session/uncheck_spec.rb +24 -20
  117. data/lib/capybara/spec/session/unselect_spec.rb +37 -37
  118. data/lib/capybara/spec/session/visit_spec.rb +48 -49
  119. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
  120. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -16
  121. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -2
  122. data/lib/capybara/spec/session/window/window_spec.rb +4 -4
  123. data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
  124. data/lib/capybara/spec/session/within_spec.rb +41 -41
  125. data/lib/capybara/spec/spec_helper.rb +11 -9
  126. data/lib/capybara/spec/test_app.rb +18 -17
  127. data/lib/capybara/spec/views/form.erb +29 -31
  128. data/lib/capybara/spec/views/with_html.erb +2 -2
  129. data/lib/capybara/version.rb +1 -1
  130. data/spec/basic_node_spec.rb +23 -23
  131. data/spec/capybara_spec.rb +20 -20
  132. data/spec/css_splitter_spec.rb +7 -7
  133. data/spec/dsl_spec.rb +37 -32
  134. data/spec/filter_set_spec.rb +4 -4
  135. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  136. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  137. data/spec/minitest_spec.rb +4 -4
  138. data/spec/minitest_spec_spec.rb +23 -23
  139. data/spec/per_session_config_spec.rb +5 -5
  140. data/spec/rack_test_spec.rb +44 -44
  141. data/spec/result_spec.rb +14 -14
  142. data/spec/rspec/features_spec.rb +13 -13
  143. data/spec/rspec/scenarios_spec.rb +4 -4
  144. data/spec/rspec/shared_spec_matchers.rb +282 -281
  145. data/spec/rspec/views_spec.rb +3 -3
  146. data/spec/rspec_matchers_spec.rb +10 -10
  147. data/spec/rspec_spec.rb +29 -29
  148. data/spec/selector_spec.rb +64 -64
  149. data/spec/selenium_spec_chrome.rb +14 -22
  150. data/spec/selenium_spec_chrome_remote.rb +28 -8
  151. data/spec/selenium_spec_edge.rb +9 -4
  152. data/spec/selenium_spec_firefox_remote.rb +87 -0
  153. data/spec/selenium_spec_ie.rb +9 -4
  154. data/spec/selenium_spec_marionette.rb +42 -18
  155. data/spec/server_spec.rb +29 -27
  156. data/spec/session_spec.rb +17 -17
  157. data/spec/shared_selenium_session.rb +70 -52
  158. data/spec/spec_helper.rb +1 -1
  159. metadata +4 -2
@@ -7,7 +7,7 @@ module Capybara
7
7
  OPTIONS = %i[always_include_port run_server default_selector default_max_wait_time ignore_hidden_elements
8
8
  automatic_reload match exact exact_text raise_server_errors visible_text_only
9
9
  automatic_label_click enable_aria_label save_path asset_host default_host app_host
10
- server_host server_port server_errors default_set_options disable_animation].freeze
10
+ server_host server_port server_errors default_set_options disable_animation test_id].freeze
11
11
 
12
12
  attr_accessor(*OPTIONS)
13
13
 
@@ -54,6 +54,8 @@ module Capybara
54
54
  # See {Capybara.configure}
55
55
  # @!method disable_animation
56
56
  # See {Capybara.configure}
57
+ # @!method test_id
58
+ # See {Capybara.configure}
57
59
 
58
60
  remove_method :server_host
59
61
 
@@ -84,10 +86,23 @@ module Capybara
84
86
 
85
87
  remove_method :disable_animation=
86
88
  def disable_animation=(bool)
87
- warn "Capybara.disable_animation is a beta feature - it may change/disappear in a future point version" if bool
89
+ warn 'Capybara.disable_animation is a beta feature - it may change/disappear in a future point version' if bool
88
90
  @disable_animation = bool
89
91
  end
90
92
 
93
+ remove_method :test_id=
94
+ ##
95
+ #
96
+ # Set an attribue to be optionally matched against the locator for builtin selector types.
97
+ # This attribute will be checked by builtin selector types whenever id would normally be checked.
98
+ # If `nil` then it will be ignored.
99
+ #
100
+ # @params [String, Symbol, nil] id Name of the attribute to use as the test id
101
+ #
102
+ def test_id=(id)
103
+ @test_id = id&.to_sym
104
+ end
105
+
91
106
  def initialize_copy(other)
92
107
  super
93
108
  @server_errors = @server_errors.dup
@@ -97,7 +112,7 @@ module Capybara
97
112
  class ReadOnlySessionConfig < SimpleDelegator
98
113
  SessionConfig::OPTIONS.each do |m|
99
114
  define_method "#{m}=" do |_|
100
- raise "Per session settings are only supported when Capybara.threadsafe == true"
115
+ raise 'Per session settings are only supported when Capybara.threadsafe == true'
101
116
  end
102
117
  end
103
118
  end
@@ -15,7 +15,7 @@ $(function() {
15
15
  $(link).after('<input type="submit" value="New Here">');
16
16
  $(link).after('<input type="text" id="new_field">');
17
17
  $('#change').remove();
18
- }, 500);
18
+ }, 1000);
19
19
  return false;
20
20
  });
21
21
  $('#slow-click').click(function() {
@@ -5,14 +5,14 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
5
5
  @session.visit('/with_js')
6
6
  end
7
7
 
8
- it "should accept the alert" do
8
+ it 'should accept the alert' do
9
9
  @session.accept_alert do
10
10
  @session.click_link('Open alert')
11
11
  end
12
12
  expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
13
13
  end
14
14
 
15
- it "should accept the alert if the text matches" do
15
+ it 'should accept the alert if the text matches' do
16
16
  @session.accept_alert 'Alert opened' do
17
17
  @session.click_link('Open alert')
18
18
  end
@@ -26,14 +26,14 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
26
26
  expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
27
27
  end
28
28
 
29
- it "should accept the alert if the text matches a regexp" do
29
+ it 'should accept the alert if the text matches a regexp' do
30
30
  @session.accept_alert(/op.{2}ed/) do
31
31
  @session.click_link('Open alert')
32
32
  end
33
33
  expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
34
34
  end
35
35
 
36
- it "should not accept the alert if the text doesnt match" do
36
+ it 'should not accept the alert if the text doesnt match' do
37
37
  expect do
38
38
  @session.accept_alert 'Incorrect Text' do
39
39
  @session.click_link('Open alert')
@@ -41,14 +41,14 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
41
41
  end.to raise_error(Capybara::ModalNotFound)
42
42
  end
43
43
 
44
- it "should return the message presented" do
44
+ it 'should return the message presented' do
45
45
  message = @session.accept_alert do
46
46
  @session.click_link('Open alert')
47
47
  end
48
48
  expect(message).to eq('Alert opened [*Yay?*]')
49
49
  end
50
50
 
51
- it "should handle the alert if the page changes" do
51
+ it 'should handle the alert if the page changes' do
52
52
  @session.accept_alert do
53
53
  @session.click_link('Alert page change')
54
54
  sleep 1 # ensure page change occurs before the accept_alert block exits
@@ -56,22 +56,22 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
56
56
  expect(@session).to have_current_path('/with_html')
57
57
  end
58
58
 
59
- context "with an asynchronous alert" do
60
- it "should accept the alert" do
59
+ context 'with an asynchronous alert' do
60
+ it 'should accept the alert' do
61
61
  @session.accept_alert do
62
62
  @session.click_link('Open delayed alert')
63
63
  end
64
64
  expect(@session).to have_xpath("//a[@id='open-delayed-alert' and @opened='true']")
65
65
  end
66
66
 
67
- it "should return the message presented" do
67
+ it 'should return the message presented' do
68
68
  message = @session.accept_alert do
69
69
  @session.click_link('Open delayed alert')
70
70
  end
71
71
  expect(message).to eq('Delayed alert opened')
72
72
  end
73
73
 
74
- it "should allow to adjust the delay" do
74
+ it 'should allow to adjust the delay' do
75
75
  @session.accept_alert wait: 10 do
76
76
  @session.click_link('Open slow alert')
77
77
  end
@@ -5,21 +5,21 @@ Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
5
5
  @session.visit('/with_js')
6
6
  end
7
7
 
8
- it "should accept the confirm" do
8
+ it 'should accept the confirm' do
9
9
  @session.accept_confirm do
10
10
  @session.click_link('Open confirm')
11
11
  end
12
12
  expect(@session).to have_xpath("//a[@id='open-confirm' and @confirmed='true']")
13
13
  end
14
14
 
15
- it "should return the message presented" do
15
+ it 'should return the message presented' do
16
16
  message = @session.accept_confirm do
17
17
  @session.click_link('Open confirm')
18
18
  end
19
19
  expect(message).to eq('Confirm opened')
20
20
  end
21
21
 
22
- it "should work with nested modals" do
22
+ it 'should work with nested modals' do
23
23
  expect do
24
24
  @session.dismiss_confirm 'Are you really sure?' do
25
25
  @session.accept_confirm 'Are you sure?' do
@@ -5,57 +5,56 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
5
5
  @session.visit('/with_js')
6
6
  end
7
7
 
8
- it "should accept the prompt with no message" do
8
+ it 'should accept the prompt with no message' do
9
9
  @session.accept_prompt do
10
10
  @session.click_link('Open prompt')
11
11
  end
12
12
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='']")
13
13
  end
14
14
 
15
- it "should accept the prompt with no message when there is a default" do
15
+ it 'should accept the prompt with no message when there is a default' do
16
16
  @session.accept_prompt do
17
17
  @session.click_link('Open defaulted prompt')
18
18
  end
19
19
  expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='Default value!']")
20
20
  end
21
21
 
22
- it "should return the message presented" do
22
+ it 'should return the message presented' do
23
23
  message = @session.accept_prompt do
24
24
  @session.click_link('Open prompt')
25
25
  end
26
26
  expect(message).to eq('Prompt opened')
27
27
  end
28
28
 
29
- it "should accept the prompt with a response" do
29
+ it 'should accept the prompt with a response' do
30
30
  @session.accept_prompt with: 'the response' do
31
31
  @session.click_link('Open prompt')
32
32
  end
33
33
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='the response']")
34
34
  end
35
35
 
36
- it "should accept the prompt with a response when there is a default" do
36
+ it 'should accept the prompt with a response when there is a default' do
37
37
  @session.accept_prompt with: 'the response' do
38
38
  @session.click_link('Open defaulted prompt')
39
39
  end
40
40
  expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='the response']")
41
41
  end
42
42
 
43
- it "should accept the prompt with a blank response when there is a default" do
44
- pending "Geckodriver doesn't set a blank response currently" if marionette?(@session)
43
+ it 'should accept the prompt with a blank response when there is a default' do
45
44
  @session.accept_prompt with: '' do
46
45
  @session.click_link('Open defaulted prompt')
47
46
  end
48
47
  expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='']")
49
48
  end
50
49
 
51
- it "should allow special characters in the reponse" do
50
+ it 'should allow special characters in the reponse' do
52
51
  @session.accept_prompt with: '\'the\' \b "response"' do
53
52
  @session.click_link('Open prompt')
54
53
  end
55
54
  expect(@session).to have_xpath(%{//a[@id='open-prompt' and @response=concat("'the' ", '\\b "response"')]})
56
55
  end
57
56
 
58
- it "should accept the prompt if the message matches" do
57
+ it 'should accept the prompt if the message matches' do
59
58
  @session.accept_prompt 'Prompt opened', with: 'matched' do
60
59
  @session.click_link('Open prompt')
61
60
  end
@@ -70,7 +69,7 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
70
69
  end.to raise_error(Capybara::ModalNotFound)
71
70
  end
72
71
 
73
- it "should return the message presented" do
72
+ it 'should return the message presented' do
74
73
  message = @session.accept_prompt with: 'the response' do
75
74
  @session.click_link('Open prompt')
76
75
  end
@@ -1,33 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#all" do
3
+ Capybara::SpecHelper.spec '#all' do
4
4
  before do
5
5
  @session.visit('/with_html')
6
6
  end
7
7
 
8
- it "should find all elements using the given locator" do
8
+ it 'should find all elements using the given locator' do
9
9
  expect(@session.all('//p').size).to eq(3)
10
10
  expect(@session.all('//h1').first.text).to eq('This is a test')
11
11
  expect(@session.all("//input[@id='test_field']").first.value).to eq('monkey')
12
12
  end
13
13
 
14
- it "should return an empty array when nothing was found" do
14
+ it 'should return an empty array when nothing was found' do
15
15
  expect(@session.all('//div[@id="nosuchthing"]')).to be_empty
16
16
  end
17
17
 
18
- it "should wait for matching elements to appear", requires: [:js] do
18
+ it 'should wait for matching elements to appear', requires: [:js] do
19
+ Capybara.default_max_wait_time = 2
19
20
  @session.visit('/with_js')
20
21
  @session.click_link('Click me')
21
- expect(@session.all(:css, "a#has-been-clicked")).not_to be_empty
22
+ expect(@session.all(:css, 'a#has-been-clicked')).not_to be_empty
22
23
  end
23
24
 
24
- it "should not wait if `minimum: 0` option is specified", requires: [:js] do
25
+ it 'should not wait if `minimum: 0` option is specified', requires: [:js] do
25
26
  @session.visit('/with_js')
26
27
  @session.click_link('Click me')
27
- expect(@session.all(:css, "a#has-been-clicked", minimum: 0)).to be_empty
28
+ expect(@session.all(:css, 'a#has-been-clicked', minimum: 0)).to be_empty
28
29
  end
29
30
 
30
- it "should accept an XPath instance", :exact_false do
31
+ it 'should accept an XPath instance', :exact_false do
31
32
  @session.visit('/form')
32
33
  @xpath = Capybara::Selector.all[:fillable_field].call('Name')
33
34
  expect(@xpath).to be_a(::XPath::Union)
@@ -35,61 +36,61 @@ Capybara::SpecHelper.spec "#all" do
35
36
  expect(@result).to include('Smith', 'John', 'John Smith')
36
37
  end
37
38
 
38
- it "should raise an error when given invalid options" do
39
- expect { @session.all('//p', schmoo: "foo") }.to raise_error(ArgumentError)
39
+ it 'should raise an error when given invalid options' do
40
+ expect { @session.all('//p', schmoo: 'foo') }.to raise_error(ArgumentError)
40
41
  end
41
42
 
42
- context "with css selectors" do
43
- it "should find all elements using the given selector" do
43
+ context 'with css selectors' do
44
+ it 'should find all elements using the given selector' do
44
45
  expect(@session.all(:css, 'h1').first.text).to eq('This is a test')
45
46
  expect(@session.all(:css, "input[id='test_field']").first.value).to eq('monkey')
46
47
  end
47
48
 
48
- it "should find all elements when given a list of selectors" do
49
+ it 'should find all elements when given a list of selectors' do
49
50
  expect(@session.all(:css, 'h1, p').size).to eq(4)
50
51
  end
51
52
  end
52
53
 
53
- context "with xpath selectors" do
54
- it "should find the first element using the given locator" do
54
+ context 'with xpath selectors' do
55
+ it 'should find the first element using the given locator' do
55
56
  expect(@session.all(:xpath, '//h1').first.text).to eq('This is a test')
56
57
  expect(@session.all(:xpath, "//input[@id='test_field']").first.value).to eq('monkey')
57
58
  end
58
59
  end
59
60
 
60
- context "with css as default selector" do
61
+ context 'with css as default selector' do
61
62
  before { Capybara.default_selector = :css }
62
63
 
63
- it "should find the first element using the given locator" do
64
+ it 'should find the first element using the given locator' do
64
65
  expect(@session.all('h1').first.text).to eq('This is a test')
65
66
  expect(@session.all("input[id='test_field']").first.value).to eq('monkey')
66
67
  end
67
68
  end
68
69
 
69
- context "with visible filter" do
70
- it "should only find visible nodes when true" do
71
- expect(@session.all(:css, "a.simple", visible: true).size).to eq(1)
70
+ context 'with visible filter' do
71
+ it 'should only find visible nodes when true' do
72
+ expect(@session.all(:css, 'a.simple', visible: true).size).to eq(1)
72
73
  end
73
74
 
74
- it "should find nodes regardless of whether they are invisible when false" do
75
- expect(@session.all(:css, "a.simple", visible: false).size).to eq(2)
75
+ it 'should find nodes regardless of whether they are invisible when false' do
76
+ expect(@session.all(:css, 'a.simple', visible: false).size).to eq(2)
76
77
  end
77
78
 
78
- it "should default to Capybara.ignore_hidden_elements" do
79
+ it 'should default to Capybara.ignore_hidden_elements' do
79
80
  Capybara.ignore_hidden_elements = true
80
- expect(@session.all(:css, "a.simple").size).to eq(1)
81
+ expect(@session.all(:css, 'a.simple').size).to eq(1)
81
82
  Capybara.ignore_hidden_elements = false
82
- expect(@session.all(:css, "a.simple").size).to eq(2)
83
+ expect(@session.all(:css, 'a.simple').size).to eq(2)
83
84
  end
84
85
 
85
- context "with per session config", requires: [:psc] do
86
- it "should use the sessions ignore_hidden_elements", psc: true do
86
+ context 'with per session config', requires: [:psc] do
87
+ it 'should use the sessions ignore_hidden_elements', psc: true do
87
88
  Capybara.ignore_hidden_elements = true
88
89
  @session.config.ignore_hidden_elements = false
89
90
  expect(Capybara.ignore_hidden_elements).to eq(true)
90
- expect(@session.all(:css, "a.simple").size).to eq(2)
91
+ expect(@session.all(:css, 'a.simple').size).to eq(2)
91
92
  @session.config.ignore_hidden_elements = true
92
- expect(@session.all(:css, "a.simple").size).to eq(1)
93
+ expect(@session.all(:css, 'a.simple').size).to eq(1)
93
94
  end
94
95
  end
95
96
  end
@@ -168,19 +169,19 @@ Capybara::SpecHelper.spec "#all" do
168
169
  end
169
170
  end
170
171
 
171
- context "within a scope" do
172
+ context 'within a scope' do
172
173
  before do
173
174
  @session.visit('/with_scope')
174
175
  end
175
176
 
176
- it "should find any element using the given locator" do
177
+ it 'should find any element using the given locator' do
177
178
  @session.within(:xpath, "//div[@id='for_bar']") do
178
179
  expect(@session.all('.//li').size).to eq(2)
179
180
  end
180
181
  end
181
182
  end
182
183
 
183
- it "should have #find_all as an alias" do
184
+ it 'should have #find_all as an alias' do
184
185
  expect(Capybara::Node::Finders.instance_method(:all)).to eq Capybara::Node::Finders.instance_method(:find_all)
185
186
  expect(@session.find_all('//p').size).to eq(3)
186
187
  end
@@ -9,64 +9,64 @@ Capybara::SpecHelper.spec '#ancestor' do
9
9
  Capybara::Selector.remove(:monkey)
10
10
  end
11
11
 
12
- it "should find the ancestor element using the given locator" do
12
+ it 'should find the ancestor element using the given locator' do
13
13
  el = @session.find(:css, '#first_image')
14
14
  expect(el.ancestor('//p')).to have_text('Lorem ipsum dolor')
15
- expect(el.ancestor("//a")[:'aria-label']).to eq('Go to simple')
15
+ expect(el.ancestor('//a')[:'aria-label']).to eq('Go to simple')
16
16
  end
17
17
 
18
- it "should find the ancestor element using the given locator and options" do
18
+ it 'should find the ancestor element using the given locator and options' do
19
19
  el = @session.find(:css, '#child')
20
20
  expect(el.ancestor('//div', text: "Ancestor\nAncestor\nAncestor")[:id]).to eq('ancestor3')
21
21
  end
22
22
 
23
- it "should raise an error if there are multiple matches" do
23
+ it 'should raise an error if there are multiple matches' do
24
24
  el = @session.find(:css, '#child')
25
25
  expect { el.ancestor('//div') }.to raise_error(Capybara::Ambiguous)
26
26
  expect { el.ancestor('//div', text: 'Ancestor') }.to raise_error(Capybara::Ambiguous)
27
27
  end
28
28
 
29
- context "with css selectors" do
30
- it "should find the first element using the given locator" do
29
+ context 'with css selectors' do
30
+ it 'should find the first element using the given locator' do
31
31
  el = @session.find(:css, '#first_image')
32
32
  expect(el.ancestor(:css, 'p')).to have_text('Lorem ipsum dolor')
33
33
  expect(el.ancestor(:css, 'a')[:'aria-label']).to eq('Go to simple')
34
34
  end
35
35
 
36
- it "should support pseudo selectors" do
36
+ it 'should support pseudo selectors' do
37
37
  el = @session.find(:css, '#button_img')
38
38
  expect(el.ancestor(:css, 'button:disabled')[:id]).to eq('ancestor_button')
39
39
  end
40
40
  end
41
41
 
42
- context "with xpath selectors" do
43
- it "should find the first element using the given locator" do
42
+ context 'with xpath selectors' do
43
+ it 'should find the first element using the given locator' do
44
44
  el = @session.find(:css, '#first_image')
45
45
  expect(el.ancestor(:xpath, '//p')).to have_text('Lorem ipsum dolor')
46
- expect(el.ancestor(:xpath, "//a")[:'aria-label']).to eq('Go to simple')
46
+ expect(el.ancestor(:xpath, '//a')[:'aria-label']).to eq('Go to simple')
47
47
  end
48
48
  end
49
49
 
50
- context "with custom selector" do
51
- it "should use the custom selector" do
50
+ context 'with custom selector' do
51
+ it 'should use the custom selector' do
52
52
  Capybara.add_selector(:level) do
53
53
  xpath { |num| ".//*[@id='ancestor#{num}']" }
54
54
  end
55
55
  el = @session.find(:css, '#child')
56
- expect(el.ancestor(:level, 1)[:id]).to eq "ancestor1"
57
- expect(el.ancestor(:level, 3)[:id]).to eq "ancestor3"
56
+ expect(el.ancestor(:level, 1)[:id]).to eq 'ancestor1'
57
+ expect(el.ancestor(:level, 3)[:id]).to eq 'ancestor3'
58
58
  end
59
59
  end
60
60
 
61
- it "should raise ElementNotFound with a useful default message if nothing was found" do
61
+ it 'should raise ElementNotFound with a useful default message if nothing was found' do
62
62
  el = @session.find(:css, '#child')
63
63
  expect do
64
64
  el.ancestor(:xpath, '//div[@id="nosuchthing"]')
65
- end.to raise_error(Capybara::ElementNotFound, "Unable to find visible xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is an ancestor of visible css \"#child\"")
65
+ end.to raise_error(Capybara::ElementNotFound, 'Unable to find xpath "//div[@id=\\"nosuchthing\\"]" that is an ancestor of visible css "#child"')
66
66
  end
67
67
 
68
- context "within a scope" do
69
- it "should limit the ancestors to inside the scope" do
68
+ context 'within a scope' do
69
+ it 'should limit the ancestors to inside the scope' do
70
70
  @session.within(:css, '#ancestor2') do
71
71
  el = @session.find(:css, '#child')
72
72
  expect(el.ancestor(:css, 'div', text: 'Ancestor')[:id]).to eq('ancestor1')
@@ -74,7 +74,7 @@ Capybara::SpecHelper.spec '#ancestor' do
74
74
  end
75
75
  end
76
76
 
77
- it "should raise if selector type is unknown" do
77
+ it 'should raise if selector type is unknown' do
78
78
  el = @session.find(:css, '#child')
79
79
  expect do
80
80
  el.ancestor(:unknown, '//h1')