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
@@ -0,0 +1 @@
1
+ ThisFileHAsNoExtension
@@ -1,14 +1,14 @@
1
1
  var activeRequests = 0;
2
2
  $(function() {
3
3
  $('#change').text('I changed it');
4
- $('#drag').draggable();
5
- $('#drop').droppable({
4
+ $('#drag, #drag_scroll').draggable();
5
+ $('#drop, #drop_scroll').droppable({
6
6
  drop: function(event, ui) {
7
7
  ui.draggable.remove();
8
8
  $(this).html('Dropped!');
9
9
  }
10
10
  });
11
- $('#clickable').click(function() {
11
+ $('#clickable').click(function(e) {
12
12
  var link = $(this);
13
13
  setTimeout(function() {
14
14
  $(link).after('<a id="has-been-clicked" href="#">Has been clicked</a>');
@@ -37,6 +37,9 @@ $(function() {
37
37
  $('#with_change_event').change(function() {
38
38
  $('body').append($('<p class="change_event_triggered"></p>').text(this.value));
39
39
  });
40
+ $('#with_change_event').on('input', function() {
41
+ $('body').append($('<p class="input_event_triggered"></p>').text(this.value));
42
+ });
40
43
  $('#checkbox_with_event').click(function() {
41
44
  $('body').append('<p id="checkbox_event_triggered">Checkbox event triggered</p>');
42
45
  });
@@ -61,12 +64,33 @@ $(function() {
61
64
  }, 400)
62
65
  });
63
66
  $('#click-test').on({
64
- dblclick: function() {
65
- $(this).after('<a id="has-been-double-clicked" href="#">Has been double clicked</a>');
67
+ click: function(e) {
68
+ var desc = "";
69
+ if (e.altKey) desc += 'alt ';
70
+ if (e.ctrlKey) desc += 'control ';
71
+ if (e.metaKey) desc += 'meta ';
72
+ if (e.shiftKey) desc += 'shift ';
73
+ var pos = this.getBoundingClientRect();
74
+ $(this).after('<a id="has-been-clicked" href="#">Has been ' + desc + 'clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
75
+ },
76
+ dblclick: function(e) {
77
+ var desc = "";
78
+ if (e.altKey) desc += 'alt ';
79
+ if (e.ctrlKey) desc += 'control ';
80
+ if (e.metaKey) desc += 'meta ';
81
+ if (e.shiftKey) desc += 'shift ';
82
+ var pos = this.getBoundingClientRect();
83
+ $(this).after('<a id="has-been-double-clicked" href="#">Has been ' + desc + 'double clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
66
84
  },
67
85
  contextmenu: function(e) {
68
86
  e.preventDefault();
69
- $(this).after('<a id="has-been-right-clicked" href="#">Has been right clicked</a>');
87
+ var desc = "";
88
+ if (e.altKey) desc += 'alt ';
89
+ if (e.ctrlKey) desc += 'control ';
90
+ if (e.metaKey) desc += 'meta ';
91
+ if (e.shiftKey) desc += 'shift ';
92
+ var pos = this.getBoundingClientRect();
93
+ $(this).after('<a id="has-been-right-clicked" href="#">Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
70
94
  }
71
95
  });
72
96
  $('#open-alert').click(function() {
@@ -106,6 +130,14 @@ $(function() {
106
130
  $(this).attr('response', response);
107
131
  }
108
132
  });
133
+ $('#open-prompt-with-default').click(function() {
134
+ var response = prompt('Prompt opened', 'Default value!');
135
+ if(response === null) {
136
+ $(this).attr('response', 'dismissed');
137
+ } else {
138
+ $(this).attr('response', response);
139
+ }
140
+ });
109
141
  $('#open-twice').click(function() {
110
142
  if (confirm('Are you sure?')) {
111
143
  if (!confirm('Are you really sure?')) {
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -19,13 +20,13 @@ Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
19
20
  end
20
21
 
21
22
  it "should work with nested modals" do
22
- expect {
23
+ expect do
23
24
  @session.dismiss_confirm 'Are you really sure?' do
24
25
  @session.accept_confirm 'Are you sure?' do
25
26
  @session.click_link('Open check twice')
26
27
  end
27
28
  end
28
- }.not_to raise_error
29
+ end.not_to raise_error
29
30
  expect(@session).to have_xpath("//a[@id='open-twice' and @confirmed='false']")
30
31
  end
31
32
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -11,6 +12,13 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
11
12
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='']")
12
13
  end
13
14
 
15
+ it "should accept the prompt with no message when there is a default" do
16
+ @session.accept_prompt do
17
+ @session.click_link('Open defaulted prompt')
18
+ end
19
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='Default value!']")
20
+ end
21
+
14
22
  it "should return the message presented" do
15
23
  message = @session.accept_prompt do
16
24
  @session.click_link('Open prompt')
@@ -25,6 +33,28 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
25
33
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='the response']")
26
34
  end
27
35
 
36
+ it "should accept the prompt with a response when there is a default" do
37
+ @session.accept_prompt with: 'the response' do
38
+ @session.click_link('Open defaulted prompt')
39
+ end
40
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='the response']")
41
+ end
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)
45
+ @session.accept_prompt with: '' do
46
+ @session.click_link('Open defaulted prompt')
47
+ end
48
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='']")
49
+ end
50
+
51
+ it "should allow special characters in the reponse" do
52
+ @session.accept_prompt with: '\'the\' \b "response"' do
53
+ @session.click_link('Open prompt')
54
+ end
55
+ expect(@session).to have_xpath(%{//a[@id='open-prompt' and @response=concat("'the' ", '\\b "response"')]})
56
+ end
57
+
28
58
  it "should accept the prompt if the message matches" do
29
59
  @session.accept_prompt 'Prompt opened', with: 'matched' do
30
60
  @session.click_link('Open prompt')
@@ -40,7 +70,6 @@ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
40
70
  end.to raise_error(Capybara::ModalNotFound)
41
71
  end
42
72
 
43
-
44
73
  it "should return the message presented" do
45
74
  message = @session.accept_prompt with: 'the response' do
46
75
  @session.click_link('Open prompt')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#all" do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -14,11 +15,23 @@ Capybara::SpecHelper.spec "#all" do
14
15
  expect(@session.all('//div[@id="nosuchthing"]')).to be_empty
15
16
  end
16
17
 
17
- it "should accept an XPath instance" do
18
+ it "should wait for matching elements to appear", requires: [:js] do
19
+ @session.visit('/with_js')
20
+ @session.click_link('Click me')
21
+ expect(@session.all(:css, "a#has-been-clicked")).not_to be_empty
22
+ end
23
+
24
+ it "should not wait if `minimum: 0` option is specified", requires: [:js] do
25
+ @session.visit('/with_js')
26
+ @session.click_link('Click me')
27
+ expect(@session.all(:css, "a#has-been-clicked", minimum: 0)).to be_empty
28
+ end
29
+
30
+ it "should accept an XPath instance", :exact_false do
18
31
  @session.visit('/form')
19
32
  @xpath = Capybara::Selector.all[:fillable_field].call('Name')
20
33
  expect(@xpath).to be_a(::XPath::Union)
21
- @result = @session.all(@xpath).map { |r| r.value }
34
+ @result = @session.all(@xpath).map(&:value)
22
35
  expect(@result).to include('Smith', 'John', 'John Smith')
23
36
  end
24
37
 
@@ -116,35 +129,35 @@ Capybara::SpecHelper.spec "#all" do
116
129
 
117
130
  context 'with multiple count filters' do
118
131
  it 'ignores other filters when :count is specified' do
119
- o = {count: 4,
120
- minimum: 5,
121
- maximum: 0,
122
- between: 0..3}
132
+ o = { count: 4,
133
+ minimum: 5,
134
+ maximum: 0,
135
+ between: 0..3 }
123
136
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
124
137
  end
125
138
  context 'with no :count expectation' do
126
139
  it 'fails if :minimum is not met' do
127
- o = {minimum: 5,
128
- maximum: 4,
129
- between: 2..7}
140
+ o = { minimum: 5,
141
+ maximum: 4,
142
+ between: 2..7 }
130
143
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
131
144
  end
132
145
  it 'fails if :maximum is not met' do
133
- o = {minimum: 0,
134
- maximum: 0,
135
- between: 2..7}
146
+ o = { minimum: 0,
147
+ maximum: 0,
148
+ between: 2..7 }
136
149
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
137
150
  end
138
151
  it 'fails if :between is not met' do
139
- o = {minimum: 0,
140
- maximum: 4,
141
- between: 0..3}
152
+ o = { minimum: 0,
153
+ maximum: 4,
154
+ between: 0..3 }
142
155
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
143
156
  end
144
157
  it 'succeeds if all combineable expectations are met' do
145
- o = {minimum: 0,
146
- maximum: 4,
147
- between: 2..7}
158
+ o = { minimum: 0,
159
+ maximum: 4,
160
+ between: 2..7 }
148
161
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
149
162
  end
150
163
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#ancestor' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -16,7 +17,7 @@ Capybara::SpecHelper.spec '#ancestor' do
16
17
 
17
18
  it "should find the ancestor element using the given locator and options" do
18
19
  el = @session.find(:css, '#child')
19
- expect(el.ancestor('//div', text: 'Ancestor Ancestor Ancestor')[:id]).to eq('ancestor3')
20
+ expect(el.ancestor('//div', text: "Ancestor\nAncestor\nAncestor")[:id]).to eq('ancestor3')
20
21
  end
21
22
 
22
23
  it "should raise an error if there are multiple matches" do
@@ -52,26 +53,23 @@ Capybara::SpecHelper.spec '#ancestor' do
52
53
  xpath { |num| ".//*[@id='ancestor#{num}']" }
53
54
  end
54
55
  el = @session.find(:css, '#child')
55
- expect(el.ancestor(:level, 1).text).to eq('Ancestor Child')
56
- expect(el.ancestor(:level, 3).text).to eq('Ancestor Ancestor Ancestor Child')
56
+ expect(el.ancestor(:level, 1)[:id]).to eq "ancestor1"
57
+ expect(el.ancestor(:level, 3)[:id]).to eq "ancestor3"
57
58
  end
58
59
  end
59
60
 
60
-
61
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 xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is an ancestor of visible css \"#child\"")
65
+ end.to raise_error(Capybara::ElementNotFound, "Unable to find visible xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is an ancestor of visible css \"#child\"")
66
66
  end
67
67
 
68
-
69
-
70
68
  context "within a scope" do
71
69
  it "should limit the ancestors to inside the scope" do
72
70
  @session.within(:css, '#ancestor2') do
73
71
  el = @session.find(:css, '#child')
74
- expect(el.ancestor(:css,'div', text: 'Ancestor')[:id]).to eq('ancestor1')
72
+ expect(el.ancestor(:css, 'div', text: 'Ancestor')[:id]).to eq('ancestor1')
75
73
  end
76
74
  end
77
75
  end
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_all_of_selectors' do
3
4
  before do
4
5
  @session.visit('/with_html')
5
6
  end
6
7
 
7
8
  it "should be true if the given selectors are on the page" do
8
- @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two" )
9
+ @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
9
10
  end
10
11
 
11
12
  it "should be false if any of the given selectors are not on the page" do
12
- expect { @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
13
+ expect { @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one") }.to raise_error(Capybara::ElementNotFound)
13
14
  end
14
15
 
15
16
  it "should use default selector" do
16
17
  Capybara.default_selector = :css
17
- expect { @session.assert_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
18
- @session.assert_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one" )
18
+ expect { @session.assert_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one") }.to raise_error(Capybara::ElementNotFound)
19
+ @session.assert_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one")
19
20
  end
20
21
 
21
22
  context "should respect scopes" do
@@ -63,7 +64,7 @@ Capybara::SpecHelper.spec '#assert_none_of_selectors' do
63
64
  end
64
65
 
65
66
  it "should be true if none of the given locators are on the page" do
66
- @session.assert_none_of_selectors(:xpath, "//abbr", "//td" )
67
+ @session.assert_none_of_selectors(:xpath, "//abbr", "//td")
67
68
  @session.assert_none_of_selectors(:css, "p a#doesnotexist", "abbr")
68
69
  end
69
70
 
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_current_path' do
3
4
  before do
4
5
  @session.visit('/with_js')
5
6
  end
6
7
 
7
8
  it "should not raise if the page has the given current path" do
8
- expect {@session.assert_current_path('/with_js')}.not_to raise_error
9
+ expect { @session.assert_current_path('/with_js') }.not_to raise_error
9
10
  end
10
11
 
11
12
  it "should allow regexp matches" do
@@ -18,27 +19,27 @@ Capybara::SpecHelper.spec '#assert_current_path' do
18
19
  end
19
20
 
20
21
  it "should raise if the page has not the given current_path" do
21
- expect{@session.assert_current_path('/with_html')}.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
22
+ expect { @session.assert_current_path('/with_html') }.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
22
23
  end
23
24
 
24
25
  it "should check query options" do
25
26
  @session.visit('/with_js?test=test')
26
- expect{@session.assert_current_path('/with_js?test=test')}.not_to raise_error
27
+ expect { @session.assert_current_path('/with_js?test=test') }.not_to raise_error
27
28
  end
28
29
 
29
30
  it "should compare the full url" do
30
- expect{@session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)}.not_to raise_error
31
+ expect { @session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true) }.not_to raise_error
31
32
  end
32
33
 
33
34
  it "should ignore the query" do
34
35
  @session.visit('/with_js?test=test')
35
- expect{@session.assert_current_path('/with_js', only_path: true)}.not_to raise_error
36
+ expect { @session.assert_current_path('/with_js', ignore_query: true) }.not_to raise_error
36
37
  end
37
38
 
38
39
  it "should not cause an exception when current_url is nil" do
39
40
  allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
40
41
 
41
- expect{@session.assert_current_path(nil)}.not_to raise_error
42
+ expect { @session.assert_current_path(nil) }.not_to raise_error
42
43
  end
43
44
  end
44
45
 
@@ -48,25 +49,25 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
48
49
  end
49
50
 
50
51
  it "should raise if the page has the given current_path" do
51
- expect{@session.assert_no_current_path('/with_js')}.to raise_error(Capybara::ExpectationNotMet)
52
+ expect { @session.assert_no_current_path('/with_js') }.to raise_error(Capybara::ExpectationNotMet)
52
53
  end
53
54
 
54
55
  it "should allow regexp matches" do
55
- expect{@session.assert_no_current_path(/monkey/)}.not_to raise_error
56
+ expect { @session.assert_no_current_path(/monkey/) }.not_to raise_error
56
57
  end
57
58
 
58
59
  it "should wait for current_path to disappear", requires: [:js] do
59
60
  @session.click_link("Change page")
60
- expect{@session.assert_no_current_path('/with_js')}.not_to raise_error
61
+ expect { @session.assert_no_current_path('/with_js') }.not_to raise_error
61
62
  end
62
63
 
63
64
  it "should not raise if the page has not the given current_path" do
64
- expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
65
+ expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
65
66
  end
66
67
 
67
68
  it "should not cause an exception when current_url is nil" do
68
69
  allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
69
70
 
70
- expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
71
+ expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
71
72
  end
72
73
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_selector' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_text' do
3
4
  it "should be true if the given text is on the page" do
4
5
  @session.visit('/with_html')
5
6
  expect(@session.assert_text('est')).to eq(true)
6
7
  expect(@session.assert_text('Lorem')).to eq(true)
7
8
  expect(@session.assert_text('Redirect')).to eq(true)
8
- expect(@session.assert_text(:'Redirect')).to eq(true)
9
- expect(@session.assert_text('text with whitespace')).to eq(true)
10
- expect(@session.assert_text("text with \n\n whitespace")).to eq(true)
9
+ expect(@session.assert_text(:Redirect)).to eq(true)
10
+ expect(@session.assert_text('text with whitespace')).to eq(true)
11
11
  end
12
12
 
13
13
  it "should take scopes into account" do
@@ -48,10 +48,18 @@ Capybara::SpecHelper.spec '#assert_text' do
48
48
  it "should raise error with a helpful message if the requested text is present but with incorrect case" do
49
49
  @session.visit('/with_html')
50
50
  expect do
51
- @session.assert_text('Text With Whitespace')
51
+ @session.assert_text('Text With Whitespace')
52
52
  end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search/)
53
53
  end
54
54
 
55
+ it "should raise error with helpful message if requested text is present but invisible and with incorrect case", requires: [:js] do
56
+ @session.visit('/with_html')
57
+ el = @session.find(:css, '#uppercase')
58
+ expect do
59
+ el.assert_text('text here')
60
+ end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search and it was found 1 time including non-visible text/)
61
+ end
62
+
55
63
  it "should raise the correct error if requested text is missing but contains regex special characters" do
56
64
  @session.visit('/with_html')
57
65
  expect do
@@ -68,7 +76,7 @@ Capybara::SpecHelper.spec '#assert_text' do
68
76
  @session.visit('/with_html')
69
77
  expect do
70
78
  @session.assert_text(/xxxxyzzz/)
71
- end.to raise_error(Capybara::ExpectationNotMet, /\Aexpected to find text matching \/xxxxyzzz\/ in "This is a test Header Class(.+)"\Z/)
79
+ end.to raise_error(Capybara::ExpectationNotMet, /\Aexpected to find text matching \/xxxxyzzz\/ in "This is a test\\nHeader Class(.+)"\Z/)
72
80
  end
73
81
 
74
82
  it "should escape any characters that would have special meaning in a regexp" do
@@ -103,7 +111,7 @@ Capybara::SpecHelper.spec '#assert_text' do
103
111
  Capybara.using_wait_time(0) do
104
112
  @session.visit('/with_js')
105
113
  @session.find(:css, '#reload-list').click
106
- @session.find(:css, '#the-list').assert_text('Foo Bar', wait: 0.9)
114
+ @session.find(:css, '#the-list').assert_text("Foo\nBar", wait: 0.9)
107
115
  end
108
116
  end
109
117
 
@@ -125,35 +133,35 @@ Capybara::SpecHelper.spec '#assert_text' do
125
133
  end
126
134
 
127
135
  it 'ignores other filters when :count is specified' do
128
- o = {count: 5,
129
- minimum: 6,
130
- maximum: 0,
131
- between: 0..4}
136
+ o = { count: 5,
137
+ minimum: 6,
138
+ maximum: 0,
139
+ between: 0..4 }
132
140
  expect { @session.assert_text('Header', o) }.not_to raise_error
133
141
  end
134
142
  context 'with no :count expectation' do
135
143
  it 'fails if :minimum is not met' do
136
- o = {minimum: 6,
137
- maximum: 5,
138
- between: 2..7}
144
+ o = { minimum: 6,
145
+ maximum: 5,
146
+ between: 2..7 }
139
147
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
140
148
  end
141
149
  it 'fails if :maximum is not met' do
142
- o = {minimum: 0,
143
- maximum: 0,
144
- between: 2..7}
150
+ o = { minimum: 0,
151
+ maximum: 0,
152
+ between: 2..7 }
145
153
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
146
154
  end
147
155
  it 'fails if :between is not met' do
148
- o = {minimum: 0,
149
- maximum: 5,
150
- between: 0..4}
156
+ o = { minimum: 0,
157
+ maximum: 5,
158
+ between: 0..4 }
151
159
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
152
160
  end
153
161
  it 'succeeds if all combineable expectations are met' do
154
- o = {minimum: 0,
155
- maximum: 5,
156
- between: 2..7}
162
+ o = { minimum: 0,
163
+ maximum: 5,
164
+ between: 2..7 }
157
165
  expect { @session.assert_text('Header', o) }.not_to raise_error
158
166
  end
159
167
  end
@@ -165,7 +173,7 @@ Capybara::SpecHelper.spec '#assert_no_text' do
165
173
  @session.visit('/with_html')
166
174
  expect do
167
175
  @session.assert_no_text('Lorem')
168
- end.to raise_error(Capybara::ExpectationNotMet, /\Aexpected not to find text "Lorem" in "This is a test Header Class.+"\Z/)
176
+ end.to raise_error(Capybara::ExpectationNotMet, /\Aexpected not to find text "Lorem" in "This is a test.*"\z/)
169
177
  end
170
178
 
171
179
  it "should be true if scoped to an element which does not have the text" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#assert_title' do
3
4
  before do
4
5
  @session.visit('/with_js')
@@ -39,11 +40,20 @@ Capybara::SpecHelper.spec '#assert_title' do
39
40
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "monkey"')
40
41
  end
41
42
 
42
- it "should normalize given title" do
43
- @session.assert_title(' with_js ')
43
+ it "should not normalize given title" do
44
+ @session.visit('/with_js')
45
+ expect { @session.assert_title(' with_js ') }.to raise_error(Capybara::ExpectationNotMet)
46
+ end
47
+
48
+ it "should match correctly normalized title" do
49
+ uri = Addressable::URI.parse('/with_title')
50
+ uri.query_values = { title: ' &nbsp; with space &nbsp;title ' }
51
+ @session.visit(uri.to_s)
52
+ @session.assert_title(' with space title')
53
+ expect { @session.assert_title('with space title') }.to raise_error(Capybara::ExpectationNotMet)
44
54
  end
45
55
 
46
- it "should normalize given title in error message" do
56
+ it "should not normalize given title in error message" do
47
57
  expect do
48
58
  @session.assert_title(2)
49
59
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "2"')