capybara 2.18.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +55 -1
  3. data/README.md +18 -17
  4. data/lib/capybara/config.rb +11 -58
  5. data/lib/capybara/cucumber.rb +2 -3
  6. data/lib/capybara/driver/base.rb +15 -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 +15 -14
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/node/actions.rb +60 -81
  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 +30 -40
  17. data/lib/capybara/node/finders.rb +62 -70
  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 +11 -7
  21. data/lib/capybara/queries/base_query.rb +22 -18
  22. data/lib/capybara/queries/current_path_query.rb +8 -24
  23. data/lib/capybara/queries/match_query.rb +3 -7
  24. data/lib/capybara/queries/selector_query.rb +92 -95
  25. data/lib/capybara/queries/sibling_query.rb +4 -4
  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 +50 -40
  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 +70 -61
  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 +131 -125
  49. data/lib/capybara/selenium/node.rb +197 -115
  50. data/lib/capybara/server.rb +3 -2
  51. data/lib/capybara/session/config.rb +47 -67
  52. data/lib/capybara/session/matchers.rb +8 -7
  53. data/lib/capybara/session.rb +138 -224
  54. data/lib/capybara/spec/public/test.js +25 -4
  55. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  56. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  57. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  58. data/lib/capybara/spec/session/all_spec.rb +31 -18
  59. data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
  60. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  61. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  62. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  63. data/lib/capybara/spec/session/assert_text.rb +23 -23
  64. data/lib/capybara/spec/session/assert_title.rb +13 -3
  65. data/lib/capybara/spec/session/attach_file_spec.rb +51 -30
  66. data/lib/capybara/spec/session/body_spec.rb +1 -0
  67. data/lib/capybara/spec/session/check_spec.rb +7 -6
  68. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  69. data/lib/capybara/spec/session/click_button_spec.rb +24 -32
  70. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  71. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  72. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  73. data/lib/capybara/spec/session/current_url_spec.rb +17 -6
  74. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  75. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  76. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  77. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  78. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  79. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  80. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  81. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
  83. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  84. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  85. data/lib/capybara/spec/session/find_field_spec.rb +9 -15
  86. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  87. data/lib/capybara/spec/session/find_spec.rb +37 -31
  88. data/lib/capybara/spec/session/first_spec.rb +60 -33
  89. data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
  90. data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  91. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  92. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  93. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  94. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  95. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  96. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  97. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  98. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  99. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  100. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  101. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  102. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  103. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  104. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  105. data/lib/capybara/spec/session/has_text_spec.rb +9 -13
  106. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  107. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  108. data/lib/capybara/spec/session/headers.rb +2 -1
  109. data/lib/capybara/spec/session/html_spec.rb +1 -0
  110. data/lib/capybara/spec/session/node_spec.rb +91 -56
  111. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  112. data/lib/capybara/spec/session/refresh_spec.rb +6 -2
  113. data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
  114. data/lib/capybara/spec/session/response_code.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  116. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  117. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  118. data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
  119. data/lib/capybara/spec/session/select_spec.rb +20 -20
  120. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  121. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  122. data/lib/capybara/spec/session/text_spec.rb +17 -3
  123. data/lib/capybara/spec/session/title_spec.rb +11 -1
  124. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  125. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  126. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  127. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  128. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  130. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  132. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  133. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  134. data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
  135. data/lib/capybara/spec/session/within_spec.rb +1 -0
  136. data/lib/capybara/spec/spec_helper.rb +34 -18
  137. data/lib/capybara/spec/test_app.rb +17 -9
  138. data/lib/capybara/spec/views/form.erb +7 -0
  139. data/lib/capybara/spec/views/with_html.erb +23 -1
  140. data/lib/capybara/spec/views/within_frames.erb +4 -1
  141. data/lib/capybara/version.rb +2 -1
  142. data/lib/capybara/window.rb +6 -10
  143. data/lib/capybara.rb +28 -25
  144. data/spec/basic_node_spec.rb +1 -0
  145. data/spec/capybara_spec.rb +11 -50
  146. data/spec/dsl_spec.rb +5 -13
  147. data/spec/filter_set_spec.rb +5 -4
  148. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  149. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  150. data/spec/minitest_spec.rb +4 -3
  151. data/spec/minitest_spec_spec.rb +3 -2
  152. data/spec/per_session_config_spec.rb +9 -8
  153. data/spec/rack_test_spec.rb +21 -20
  154. data/spec/result_spec.rb +17 -16
  155. data/spec/rspec/features_spec.rb +17 -14
  156. data/spec/rspec/scenarios_spec.rb +5 -7
  157. data/spec/rspec/shared_spec_matchers.rb +96 -99
  158. data/spec/rspec/views_spec.rb +2 -1
  159. data/spec/rspec_matchers_spec.rb +18 -2
  160. data/spec/rspec_spec.rb +11 -15
  161. data/spec/selector_spec.rb +5 -6
  162. data/spec/selenium_spec_chrome.rb +9 -4
  163. data/spec/selenium_spec_edge.rb +27 -0
  164. data/spec/selenium_spec_ie.rb +31 -0
  165. data/spec/selenium_spec_marionette.rb +28 -12
  166. data/spec/server_spec.rb +33 -33
  167. data/spec/session_spec.rb +2 -1
  168. data/spec/shared_selenium_session.rb +36 -22
  169. data/spec/spec_helper.rb +3 -6
  170. metadata +68 -85
  171. data/lib/capybara/query.rb +0 -7
  172. data/spec/selenium_spec_firefox.rb +0 -68
@@ -8,7 +8,7 @@ $(function() {
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>');
@@ -64,12 +64,33 @@ $(function() {
64
64
  }, 400)
65
65
  });
66
66
  $('#click-test').on({
67
- dblclick: function() {
68
- $(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>');
69
84
  },
70
85
  contextmenu: function(e) {
71
86
  e.preventDefault();
72
- $(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>');
73
94
  }
74
95
  });
75
96
  $('#open-alert').click(function() {
@@ -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')
@@ -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,7 +48,7 @@ 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
 
@@ -76,7 +76,7 @@ Capybara::SpecHelper.spec '#assert_text' do
76
76
  @session.visit('/with_html')
77
77
  expect do
78
78
  @session.assert_text(/xxxxyzzz/)
79
- 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/)
80
80
  end
81
81
 
82
82
  it "should escape any characters that would have special meaning in a regexp" do
@@ -111,7 +111,7 @@ Capybara::SpecHelper.spec '#assert_text' do
111
111
  Capybara.using_wait_time(0) do
112
112
  @session.visit('/with_js')
113
113
  @session.find(:css, '#reload-list').click
114
- @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)
115
115
  end
116
116
  end
117
117
 
@@ -133,35 +133,35 @@ Capybara::SpecHelper.spec '#assert_text' do
133
133
  end
134
134
 
135
135
  it 'ignores other filters when :count is specified' do
136
- o = {count: 5,
137
- minimum: 6,
138
- maximum: 0,
139
- between: 0..4}
136
+ o = { count: 5,
137
+ minimum: 6,
138
+ maximum: 0,
139
+ between: 0..4 }
140
140
  expect { @session.assert_text('Header', o) }.not_to raise_error
141
141
  end
142
142
  context 'with no :count expectation' do
143
143
  it 'fails if :minimum is not met' do
144
- o = {minimum: 6,
145
- maximum: 5,
146
- between: 2..7}
144
+ o = { minimum: 6,
145
+ maximum: 5,
146
+ between: 2..7 }
147
147
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
148
148
  end
149
149
  it 'fails if :maximum is not met' do
150
- o = {minimum: 0,
151
- maximum: 0,
152
- between: 2..7}
150
+ o = { minimum: 0,
151
+ maximum: 0,
152
+ between: 2..7 }
153
153
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
154
154
  end
155
155
  it 'fails if :between is not met' do
156
- o = {minimum: 0,
157
- maximum: 5,
158
- between: 0..4}
156
+ o = { minimum: 0,
157
+ maximum: 5,
158
+ between: 0..4 }
159
159
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
160
160
  end
161
161
  it 'succeeds if all combineable expectations are met' do
162
- o = {minimum: 0,
163
- maximum: 5,
164
- between: 2..7}
162
+ o = { minimum: 0,
163
+ maximum: 5,
164
+ between: 2..7 }
165
165
  expect { @session.assert_text('Header', o) }.not_to raise_error
166
166
  end
167
167
  end
@@ -173,7 +173,7 @@ Capybara::SpecHelper.spec '#assert_no_text' do
173
173
  @session.visit('/with_html')
174
174
  expect do
175
175
  @session.assert_no_text('Lorem')
176
- 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/)
177
177
  end
178
178
 
179
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"')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#attach_file" do
3
4
  before do
4
5
  @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
@@ -10,19 +11,19 @@ Capybara::SpecHelper.spec "#attach_file" do
10
11
 
11
12
  context "with normal form" do
12
13
  it "should set a file path by id" do
13
- @session.attach_file "form_image", __FILE__
14
+ @session.attach_file "form_image", with_os_path_separators(__FILE__)
14
15
  @session.click_button('awesome')
15
16
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
16
17
  end
17
18
 
18
19
  it "should set a file path by label" do
19
- @session.attach_file "Image", __FILE__
20
+ @session.attach_file "Image", with_os_path_separators(__FILE__)
20
21
  @session.click_button('awesome')
21
22
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
22
23
  end
23
24
 
24
25
  it "casts to string" do
25
- @session.attach_file :"form_image", __FILE__
26
+ @session.attach_file :form_image, with_os_path_separators(__FILE__)
26
27
  @session.click_button('awesome')
27
28
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
28
29
  end
@@ -30,13 +31,13 @@ Capybara::SpecHelper.spec "#attach_file" do
30
31
 
31
32
  context "with multipart form" do
32
33
  it "should set a file path by id" do
33
- @session.attach_file "form_document", @test_file_path
34
+ @session.attach_file "form_document", with_os_path_separators(@test_file_path)
34
35
  @session.click_button('Upload Single')
35
36
  expect(@session).to have_content(File.read(@test_file_path))
36
37
  end
37
38
 
38
39
  it "should set a file path by label" do
39
- @session.attach_file "Single Document", @test_file_path
40
+ @session.attach_file "Single Document", with_os_path_separators(@test_file_path)
40
41
  @session.click_button('Upload Single')
41
42
  expect(@session).to have_content(File.read(@test_file_path))
42
43
  end
@@ -47,35 +48,35 @@ Capybara::SpecHelper.spec "#attach_file" do
47
48
  end
48
49
 
49
50
  it "should send content type text/plain when uploading a text file" do
50
- @session.attach_file "Single Document", @test_file_path
51
+ @session.attach_file "Single Document", with_os_path_separators(@test_file_path)
51
52
  @session.click_button 'Upload Single'
52
53
  expect(@session).to have_content('text/plain')
53
54
  end
54
55
 
55
56
  it "should send content type image/jpeg when uploading an image" do
56
- @session.attach_file "Single Document", @test_jpg_file_path
57
+ @session.attach_file "Single Document", with_os_path_separators(@test_jpg_file_path)
57
58
  @session.click_button 'Upload Single'
58
59
  expect(@session).to have_content('image/jpeg')
59
60
  end
60
61
 
61
62
  it "should not break when uploading a file without extension" do
62
- @session.attach_file "Single Document", @no_extension_file_path
63
+ @session.attach_file "Single Document", with_os_path_separators(@no_extension_file_path)
63
64
  @session.click_button 'Upload Single'
64
65
  expect(@session).to have_content(File.read(@no_extension_file_path))
65
66
  end
66
67
 
67
68
  it "should not break when using HTML5 multiple file input" do
68
- @session.attach_file "Multiple Documents", @test_file_path
69
+ @session.attach_file "Multiple Documents", with_os_path_separators(@test_file_path)
69
70
  @session.click_button('Upload Multiple')
70
71
  expect(@session).to have_content(File.read(@test_file_path))
71
- expect(@session.body).to include("1 | ")#number of files
72
+ expect(@session.body).to include("1 | ") # number of files
72
73
  end
73
74
 
74
- it "should not break when using HTML5 multiple file input uploading multiple files" do
75
- pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode.to_s =~ /^selenium_(firefox|marionette)/
76
- @session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
75
+ it "should not break when using HTML5 multiple file input uploading multiple files" do
76
+ @session.attach_file("Multiple Documents",
77
+ [@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
77
78
  @session.click_button('Upload Multiple')
78
- expect(@session.body).to include("2 | ")#number of files
79
+ expect(@session.body).to include("2 | ") # number of files
79
80
  expect(@session.body).to include(File.read(@test_file_path))
80
81
  expect(@session.body).to include(File.read(@another_test_file_path))
81
82
  end
@@ -84,13 +85,23 @@ Capybara::SpecHelper.spec "#attach_file" do
84
85
  @session.click_button('Upload Empty Multiple')
85
86
  expect(@session).to have_content("Successfully ignored empty file field")
86
87
  end
88
+
89
+ it "should not append files to already attached" do
90
+ @session.attach_file "Multiple Documents", with_os_path_separators(@test_file_path)
91
+ @session.attach_file("Multiple Documents",
92
+ [@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
93
+ @session.click_button('Upload Multiple')
94
+ expect(@session.body).to include("2 | ") # number of files
95
+ expect(@session.body).to include(File.read(@test_file_path))
96
+ expect(@session.body).to include(File.read(@another_test_file_path))
97
+ end
87
98
  end
88
99
 
89
100
  context "with a locator that doesn't exist" do
90
101
  it "should raise an error" do
91
102
  msg = "Unable to find visible file field \"does not exist\" that is not disabled"
92
103
  expect do
93
- @session.attach_file('does not exist', @test_file_path)
104
+ @session.attach_file('does not exist', with_os_path_separators(@test_file_path))
94
105
  end.to raise_error(Capybara::ElementNotFound, msg)
95
106
  end
96
107
  end
@@ -103,45 +114,55 @@ Capybara::SpecHelper.spec "#attach_file" do
103
114
 
104
115
  context "with :exact option" do
105
116
  it "should set a file path by partial label when false" do
106
- @session.attach_file "Imag", __FILE__, exact: false
117
+ @session.attach_file "Imag", with_os_path_separators(__FILE__), exact: false
107
118
  @session.click_button('awesome')
108
119
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
109
120
  end
110
121
 
111
- it "not allow partial matches when true" do
122
+ it "should not allow partial matches when true" do
112
123
  expect do
113
- @session.attach_file "Imag", __FILE__, exact: true
124
+ @session.attach_file "Imag", with_os_path_separators(__FILE__), exact: true
114
125
  end.to raise_error(Capybara::ElementNotFound)
115
126
  end
116
127
  end
117
128
 
118
- context "with :make_visible option", requires: [:js, :es_args] do
129
+ context "with :make_visible option", requires: %i[js es_args] do
119
130
  it "applies a default style change when true" do
120
131
  @session.visit('/with_js')
121
- expect { @session.attach_file("hidden_file", __FILE__) }.to raise_error Capybara::ElementNotFound
122
- expect {
123
- @session.attach_file("hidden_file", __FILE__, make_visible: true)
124
- }.not_to raise_error
132
+ expect do
133
+ @session.attach_file("hidden_file", with_os_path_separators(__FILE__))
134
+ end.to raise_error Capybara::ElementNotFound
135
+ expect do
136
+ @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: true)
137
+ end.not_to raise_error
125
138
  end
126
139
 
127
140
  it "accepts a hash of styles to be applied" do
128
141
  @session.visit('/with_js')
129
- expect {
130
- @session.attach_file("hidden_file", __FILE__, make_visible: { opacity: 1, display: 'block' })
131
- }.not_to raise_error
142
+ expect do
143
+ @session.attach_file("hidden_file",
144
+ with_os_path_separators(__FILE__),
145
+ make_visible: { opacity: 1, display: 'block' })
146
+ end.not_to raise_error
132
147
  end
133
148
 
134
149
  it "raises an error when the file input is not made visible" do
135
150
  @session.visit('/with_js')
136
- expect {
137
- @session.attach_file("hidden_file", __FILE__, make_visible: { color: 'red' })
138
- }.to raise_error(Capybara::ExpectationNotMet)
151
+ expect do
152
+ @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: { color: 'red' })
153
+ end.to raise_error(Capybara::ExpectationNotMet)
139
154
  end
140
155
 
141
156
  it "resets the style when done" do
142
157
  @session.visit('/with_js')
143
- @session.attach_file("hidden_file", __FILE__, make_visible: true)
158
+ @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: true)
144
159
  expect(@session.evaluate_script("arguments[0].style.display", @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
145
160
  end
146
161
  end
162
+
163
+ private
164
+
165
+ def with_os_path_separators(path)
166
+ Gem.win_platform? ? path.to_s.tr('/', '\\') : path.to_s
167
+ end
147
168
  end