capybara 2.18.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +26 -1
  3. data/README.md +12 -12
  4. data/lib/capybara.rb +13 -25
  5. data/lib/capybara/config.rb +11 -57
  6. data/lib/capybara/cucumber.rb +2 -3
  7. data/lib/capybara/driver/base.rb +5 -16
  8. data/lib/capybara/driver/node.rb +5 -4
  9. data/lib/capybara/dsl.rb +1 -0
  10. data/lib/capybara/helpers.rb +16 -28
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/minitest/spec.rb +15 -14
  13. data/lib/capybara/node/actions.rb +59 -81
  14. data/lib/capybara/node/base.rb +11 -18
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +8 -8
  17. data/lib/capybara/node/element.rb +30 -40
  18. data/lib/capybara/node/finders.rb +62 -70
  19. data/lib/capybara/node/matchers.rb +48 -71
  20. data/lib/capybara/node/simple.rb +11 -17
  21. data/lib/capybara/queries/ancestor_query.rb +4 -6
  22. data/lib/capybara/queries/base_query.rb +18 -17
  23. data/lib/capybara/queries/current_path_query.rb +8 -24
  24. data/lib/capybara/queries/match_query.rb +3 -7
  25. data/lib/capybara/queries/selector_query.rb +92 -95
  26. data/lib/capybara/queries/sibling_query.rb +4 -4
  27. data/lib/capybara/queries/text_query.rb +37 -34
  28. data/lib/capybara/queries/title_query.rb +8 -11
  29. data/lib/capybara/rack_test/browser.rb +15 -18
  30. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  31. data/lib/capybara/rack_test/driver.rb +6 -10
  32. data/lib/capybara/rack_test/form.rb +50 -40
  33. data/lib/capybara/rack_test/node.rb +70 -56
  34. data/lib/capybara/rails.rb +2 -6
  35. data/lib/capybara/result.rb +22 -22
  36. data/lib/capybara/rspec.rb +5 -10
  37. data/lib/capybara/rspec/compound.rb +5 -10
  38. data/lib/capybara/rspec/features.rb +17 -48
  39. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  40. data/lib/capybara/rspec/matchers.rb +70 -60
  41. data/lib/capybara/selector.rb +129 -117
  42. data/lib/capybara/selector/css.rb +6 -11
  43. data/lib/capybara/selector/filter.rb +1 -17
  44. data/lib/capybara/selector/filter_set.rb +17 -14
  45. data/lib/capybara/selector/filters/base.rb +7 -6
  46. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  47. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  48. data/lib/capybara/selector/selector.rb +27 -33
  49. data/lib/capybara/selenium/driver.rb +113 -127
  50. data/lib/capybara/selenium/node.rb +148 -113
  51. data/lib/capybara/server.rb +3 -2
  52. data/lib/capybara/session.rb +137 -223
  53. data/lib/capybara/session/config.rb +47 -67
  54. data/lib/capybara/session/matchers.rb +8 -7
  55. data/lib/capybara/spec/public/test.js +26 -4
  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 +1 -0
  59. data/lib/capybara/spec/session/all_spec.rb +31 -18
  60. data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
  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 +18 -17
  65. data/lib/capybara/spec/session/assert_title.rb +1 -0
  66. data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
  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 +20 -28
  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 +7 -6
  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 +3 -2
  81. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  83. data/lib/capybara/spec/session/fill_in_spec.rb +6 -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 +8 -14
  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/switch_to_frame_spec.rb +2 -1
  91. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  92. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  93. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  94. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  95. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  96. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  97. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  98. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  99. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  100. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  101. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  102. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  103. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  104. data/lib/capybara/spec/session/has_text_spec.rb +6 -5
  105. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  106. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  107. data/lib/capybara/spec/session/headers.rb +2 -1
  108. data/lib/capybara/spec/session/html_spec.rb +1 -0
  109. data/lib/capybara/spec/session/node_spec.rb +91 -56
  110. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  111. data/lib/capybara/spec/session/refresh_spec.rb +4 -2
  112. data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
  113. data/lib/capybara/spec/session/response_code.rb +1 -0
  114. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  116. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  117. data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
  118. data/lib/capybara/spec/session/select_spec.rb +20 -20
  119. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  120. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  121. data/lib/capybara/spec/session/text_spec.rb +1 -0
  122. data/lib/capybara/spec/session/title_spec.rb +1 -1
  123. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  124. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  125. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  126. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  127. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  128. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  130. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  132. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  133. data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
  134. data/lib/capybara/spec/session/within_spec.rb +1 -0
  135. data/lib/capybara/spec/spec_helper.rb +26 -18
  136. data/lib/capybara/spec/test_app.rb +8 -9
  137. data/lib/capybara/spec/views/form.erb +1 -0
  138. data/lib/capybara/spec/views/with_html.erb +3 -1
  139. data/lib/capybara/spec/views/within_frames.erb +4 -1
  140. data/lib/capybara/version.rb +2 -1
  141. data/lib/capybara/window.rb +6 -10
  142. data/spec/basic_node_spec.rb +1 -0
  143. data/spec/capybara_spec.rb +9 -32
  144. data/spec/dsl_spec.rb +5 -13
  145. data/spec/filter_set_spec.rb +5 -4
  146. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  147. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  148. data/spec/minitest_spec.rb +4 -3
  149. data/spec/minitest_spec_spec.rb +3 -2
  150. data/spec/per_session_config_spec.rb +9 -8
  151. data/spec/rack_test_spec.rb +21 -20
  152. data/spec/result_spec.rb +17 -16
  153. data/spec/rspec/features_spec.rb +17 -14
  154. data/spec/rspec/scenarios_spec.rb +5 -7
  155. data/spec/rspec/shared_spec_matchers.rb +96 -99
  156. data/spec/rspec/views_spec.rb +2 -1
  157. data/spec/rspec_matchers_spec.rb +19 -2
  158. data/spec/rspec_spec.rb +11 -15
  159. data/spec/selector_spec.rb +5 -6
  160. data/spec/selenium_spec_chrome.rb +7 -4
  161. data/spec/selenium_spec_marionette.rb +26 -12
  162. data/spec/server_spec.rb +33 -33
  163. data/spec/session_spec.rb +2 -1
  164. data/spec/shared_selenium_session.rb +27 -21
  165. data/spec/spec_helper.rb +2 -5
  166. metadata +66 -87
  167. data/lib/capybara/query.rb +0 -7
  168. data/spec/selenium_spec_firefox.rb +0 -68
@@ -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,11 +1,12 @@
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(:Redirect)).to eq(true)
9
10
  expect(@session.assert_text('text with whitespace')).to eq(true)
10
11
  expect(@session.assert_text("text with \n\n whitespace")).to eq(true)
11
12
  end
@@ -133,35 +134,35 @@ Capybara::SpecHelper.spec '#assert_text' do
133
134
  end
134
135
 
135
136
  it 'ignores other filters when :count is specified' do
136
- o = {count: 5,
137
- minimum: 6,
138
- maximum: 0,
139
- between: 0..4}
137
+ o = { count: 5,
138
+ minimum: 6,
139
+ maximum: 0,
140
+ between: 0..4 }
140
141
  expect { @session.assert_text('Header', o) }.not_to raise_error
141
142
  end
142
143
  context 'with no :count expectation' do
143
144
  it 'fails if :minimum is not met' do
144
- o = {minimum: 6,
145
- maximum: 5,
146
- between: 2..7}
145
+ o = { minimum: 6,
146
+ maximum: 5,
147
+ between: 2..7 }
147
148
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
148
149
  end
149
150
  it 'fails if :maximum is not met' do
150
- o = {minimum: 0,
151
- maximum: 0,
152
- between: 2..7}
151
+ o = { minimum: 0,
152
+ maximum: 0,
153
+ between: 2..7 }
153
154
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
154
155
  end
155
156
  it 'fails if :between is not met' do
156
- o = {minimum: 0,
157
- maximum: 5,
158
- between: 0..4}
157
+ o = { minimum: 0,
158
+ maximum: 5,
159
+ between: 0..4 }
159
160
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
160
161
  end
161
162
  it 'succeeds if all combineable expectations are met' do
162
- o = {minimum: 0,
163
- maximum: 5,
164
- between: 2..7}
163
+ o = { minimum: 0,
164
+ maximum: 5,
165
+ between: 2..7 }
165
166
  expect { @session.assert_text('Header', o) }.not_to raise_error
166
167
  end
167
168
  end
@@ -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')
@@ -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__))
@@ -22,7 +23,7 @@ Capybara::SpecHelper.spec "#attach_file" do
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, __FILE__
26
27
  @session.click_button('awesome')
27
28
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
28
29
  end
@@ -68,14 +69,14 @@ Capybara::SpecHelper.spec "#attach_file" do
68
69
  @session.attach_file "Multiple Documents", @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
+ it "should not break when using HTML5 multiple file input uploading multiple files" do
75
76
  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
77
  @session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
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
@@ -108,34 +109,34 @@ Capybara::SpecHelper.spec "#attach_file" do
108
109
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
109
110
  end
110
111
 
111
- it "not allow partial matches when true" do
112
+ it "should not allow partial matches when true" do
112
113
  expect do
113
- @session.attach_file "Imag", __FILE__, exact: true
114
+ @session.attach_file "Imag", __FILE__, exact: true
114
115
  end.to raise_error(Capybara::ElementNotFound)
115
116
  end
116
117
  end
117
118
 
118
- context "with :make_visible option", requires: [:js, :es_args] do
119
+ context "with :make_visible option", requires: %i[js es_args] do
119
120
  it "applies a default style change when true" do
120
121
  @session.visit('/with_js')
121
122
  expect { @session.attach_file("hidden_file", __FILE__) }.to raise_error Capybara::ElementNotFound
122
- expect {
123
+ expect do
123
124
  @session.attach_file("hidden_file", __FILE__, make_visible: true)
124
- }.not_to raise_error
125
+ end.not_to raise_error
125
126
  end
126
127
 
127
128
  it "accepts a hash of styles to be applied" do
128
129
  @session.visit('/with_js')
129
- expect {
130
+ expect do
130
131
  @session.attach_file("hidden_file", __FILE__, make_visible: { opacity: 1, display: 'block' })
131
- }.not_to raise_error
132
+ end.not_to raise_error
132
133
  end
133
134
 
134
135
  it "raises an error when the file input is not made visible" do
135
136
  @session.visit('/with_js')
136
- expect {
137
+ expect do
137
138
  @session.attach_file("hidden_file", __FILE__, make_visible: { color: 'red' })
138
- }.to raise_error(Capybara::ExpectationNotMet)
139
+ end.to raise_error(Capybara::ExpectationNotMet)
139
140
  end
140
141
 
141
142
  it "resets the style when done" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#body' do
3
4
  it "should return the unmodified page body" do
4
5
  @session.visit('/')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#check" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -18,7 +19,7 @@ Capybara::SpecHelper.spec "#check" do
18
19
  it "should trigger associated events", requires: [:js] do
19
20
  @session.visit('/with_js')
20
21
  @session.check('checkbox_with_event')
21
- expect(@session).to have_css('#checkbox_event_triggered');
22
+ expect(@session).to have_css('#checkbox_event_triggered')
22
23
  end
23
24
 
24
25
  describe "checking" do
@@ -62,7 +63,7 @@ Capybara::SpecHelper.spec "#check" do
62
63
  end
63
64
 
64
65
  it "casts to string" do
65
- @session.check(:"form_pets_cat")
66
+ @session.check(:form_pets_cat)
66
67
  @session.click_button('awesome')
67
68
  expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
68
69
  end
@@ -86,14 +87,14 @@ Capybara::SpecHelper.spec "#check" do
86
87
 
87
88
  context "with :exact option" do
88
89
  it "should accept partial matches when false" do
89
- @session.check('Ham', exact: false)
90
+ @session.check('Ham', exact: false)
90
91
  @session.click_button('awesome')
91
92
  expect(extract_results(@session)['pets']).to include('hamster')
92
93
  end
93
94
 
94
95
  it "should not accept partial matches when true" do
95
96
  expect do
96
- @session.check('Ham', exact: true)
97
+ @session.check('Ham', exact: true)
97
98
  end.to raise_error(Capybara::ElementNotFound)
98
99
  end
99
100
  end
@@ -146,7 +147,7 @@ Capybara::SpecHelper.spec "#check" do
146
147
  end
147
148
 
148
149
  it "should raise error if not allowed to click label" do
149
- expect{@session.check('form_cars_mclaren', allow_label_click: false)}.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
150
+ expect { @session.check('form_cars_mclaren', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
150
151
  end
151
152
  end
152
153
 
@@ -158,7 +159,7 @@ Capybara::SpecHelper.spec "#check" do
158
159
  end
159
160
 
160
161
  it "should raise error if checkbox not visible" do
161
- expect{@session.check('form_cars_mclaren')}.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
162
+ expect { @session.check('form_cars_mclaren') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
162
163
  end
163
164
 
164
165
  context "with allow_label_click == true" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#choose" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -18,7 +19,7 @@ Capybara::SpecHelper.spec "#choose" do
18
19
 
19
20
  it "casts to string" do
20
21
  @session.choose("Both")
21
- @session.click_button(:'awesome')
22
+ @session.click_button(:awesome)
22
23
  expect(extract_results(@session)['gender']).to eq('both')
23
24
  end
24
25
 
@@ -41,14 +42,14 @@ Capybara::SpecHelper.spec "#choose" do
41
42
 
42
43
  context "with :exact option" do
43
44
  it "should accept partial matches when false" do
44
- @session.choose("Mal", exact: false)
45
+ @session.choose("Mal", exact: false)
45
46
  @session.click_button('awesome')
46
47
  expect(extract_results(@session)['gender']).to eq('male')
47
48
  end
48
49
 
49
50
  it "should not accept partial matches when true" do
50
51
  expect do
51
- @session.choose("Mal", exact: true)
52
+ @session.choose("Mal", exact: true)
52
53
  end.to raise_error(Capybara::ElementNotFound)
53
54
  end
54
55
  end
@@ -82,7 +83,7 @@ Capybara::SpecHelper.spec "#choose" do
82
83
  end
83
84
 
84
85
  it "should raise error if not allowed to click label" do
85
- expect{@session.choose("party_democrat", allow_label_click: false)}.to raise_error(Capybara::ElementNotFound, 'Unable to find visible radio button "party_democrat" that is not disabled')
86
+ expect { @session.choose("party_democrat", allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible radio button "party_democrat" that is not disabled')
86
87
  end
87
88
  end
88
89
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#click_button' do
3
4
  before do
4
5
  @session.visit('/form')
@@ -151,25 +152,18 @@ Capybara::SpecHelper.spec '#click_button' do
151
152
  end
152
153
  end
153
154
 
154
- context "with id given on a submit button" do
155
- it "should submit the associated form" do
155
+ context "input type=submit button" do
156
+ it "should submit by button id" do
156
157
  @session.click_button('awe123')
157
158
  expect(extract_results(@session)['first_name']).to eq('John')
158
159
  end
159
160
 
160
- it "should work with partial matches" do
161
- @session.click_button('Go')
162
- expect(@session).to have_content('You landed')
163
- end
164
- end
165
-
166
- context "with title given on a submit button" do
167
- it "should submit the associated form" do
161
+ it "should submit by button title" do
168
162
  @session.click_button('What an Awesome Button')
169
163
  expect(extract_results(@session)['first_name']).to eq('John')
170
164
  end
171
165
 
172
- it "should work with partial matches" do
166
+ it "should submit by partial title", :exact_false do
173
167
  @session.click_button('What an Awesome')
174
168
  expect(extract_results(@session)['first_name']).to eq('John')
175
169
  end
@@ -198,7 +192,6 @@ Capybara::SpecHelper.spec '#click_button' do
198
192
  end
199
193
  end
200
194
 
201
-
202
195
  context "with submit button outside the form defined by <button> tag" do
203
196
  before do
204
197
  @session.click_button('outside_button')
@@ -250,20 +243,19 @@ Capybara::SpecHelper.spec '#click_button' do
250
243
  expect(extract_results(@session)['first_name']).to eq('John')
251
244
  end
252
245
 
253
- it "should work with partial matches" do
246
+ it "should work with partial matches", :exact_false do
254
247
  @session.click_button('hai')
255
248
  expect(extract_results(@session)['first_name']).to eq('John')
256
249
  end
257
250
  end
258
251
 
259
-
260
252
  context "with value given on an image button" do
261
253
  it "should submit the associated form" do
262
254
  @session.click_button('okay')
263
255
  expect(extract_results(@session)['first_name']).to eq('John')
264
256
  end
265
257
 
266
- it "should work with partial matches" do
258
+ it "should work with partial matches", :exact_false do
267
259
  @session.click_button('kay')
268
260
  expect(extract_results(@session)['first_name']).to eq('John')
269
261
  end
@@ -282,7 +274,7 @@ Capybara::SpecHelper.spec '#click_button' do
282
274
  expect(extract_results(@session)['first_name']).to eq('John')
283
275
  end
284
276
 
285
- it "should work with partial matches" do
277
+ it "should work with partial matches", :exact_false do
286
278
  @session.click_button('Okay 556')
287
279
  expect(extract_results(@session)['first_name']).to eq('John')
288
280
  end
@@ -290,17 +282,17 @@ Capybara::SpecHelper.spec '#click_button' do
290
282
 
291
283
  context "with text given on a button defined by <button> tag" do
292
284
  it "should submit the associated form" do
293
- @session.click_button('Click me')
285
+ @session.click_button('Click me!')
294
286
  expect(extract_results(@session)['first_name']).to eq('John')
295
287
  end
296
288
 
297
- it "should work with partial matches" do
289
+ it "should work with partial matches", :exact_false do
298
290
  @session.click_button('Click')
299
291
  expect(extract_results(@session)['first_name']).to eq('John')
300
292
  end
301
293
  end
302
294
 
303
- context "with id given on a button defined by <button> tag" do
295
+ context "with id given on a button defined by <button> tag" do
304
296
  it "should submit the associated form" do
305
297
  @session.click_button('click_me_123')
306
298
  expect(extract_results(@session)['first_name']).to eq('John')
@@ -315,13 +307,13 @@ Capybara::SpecHelper.spec '#click_button' do
315
307
  end
316
308
  end
317
309
 
318
- context "with value given on a button defined by <button> tag" do
310
+ context "with value given on a button defined by <button> tag" do
319
311
  it "should submit the associated form" do
320
312
  @session.click_button('click_me')
321
313
  expect(extract_results(@session)['first_name']).to eq('John')
322
314
  end
323
315
 
324
- it "should work with partial matches" do
316
+ it "should work with partial matches", :exact_false do
325
317
  @session.click_button('ck_me')
326
318
  expect(extract_results(@session)['first_name']).to eq('John')
327
319
  end
@@ -333,7 +325,7 @@ Capybara::SpecHelper.spec '#click_button' do
333
325
  expect(extract_results(@session)['first_name']).to eq('John')
334
326
  end
335
327
 
336
- it "should work with partial matches" do
328
+ it "should work with partial matches", :exact_false do
337
329
  @session.click_button('Click Title')
338
330
  expect(extract_results(@session)['first_name']).to eq('John')
339
331
  end
@@ -345,7 +337,7 @@ Capybara::SpecHelper.spec '#click_button' do
345
337
  expect(extract_results(@session)['first_name']).to eq('John')
346
338
  end
347
339
 
348
- it "should work with partial matches" do
340
+ it "should work with partial matches", :exact_false do
349
341
  @session.click_button('se eating h')
350
342
  expect(extract_results(@session)['first_name']).to eq('John')
351
343
  end
@@ -424,15 +416,15 @@ Capybara::SpecHelper.spec '#click_button' do
424
416
 
425
417
  it "should encode complex field names, like array[][value]" do
426
418
  @session.visit('/form')
427
- @session.fill_in('address1_city', :with =>'Paris')
428
- @session.fill_in('address1_street', :with =>'CDG')
419
+ @session.fill_in('address1_city', with: 'Paris')
420
+ @session.fill_in('address1_street', with: 'CDG')
429
421
 
430
422
  @session.fill_in('address2_city', with: 'Mikolaiv')
431
423
  @session.fill_in('address2_street', with: 'PGS')
432
424
 
433
425
  @session.click_button "awesome"
434
426
 
435
- addresses=extract_results(@session)["addresses"]
427
+ addresses = extract_results(@session)["addresses"]
436
428
  expect(addresses.size).to eq(2)
437
429
 
438
430
  expect(addresses[0]["street"]).to eq('CDG')
@@ -446,13 +438,13 @@ Capybara::SpecHelper.spec '#click_button' do
446
438
 
447
439
  context "with :exact option" do
448
440
  it "should accept partial matches when false" do
449
- @session.click_button('What an Awesome', exact: false)
441
+ @session.click_button('What an Awesome', exact: false)
450
442
  expect(extract_results(@session)['first_name']).to eq('John')
451
443
  end
452
444
 
453
445
  it "should not accept partial matches when true" do
454
446
  expect do
455
- @session.click_button('What an Awesome', exact: true)
447
+ @session.click_button('What an Awesome', exact: true)
456
448
  end.to raise_error(Capybara::ElementNotFound)
457
449
  end
458
450
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#click_link_or_button' do
3
4
  it "should click on a link" do
4
5
  @session.visit('/with_html')
@@ -32,31 +33,31 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
32
33
 
33
34
  it "casts to string" do
34
35
  @session.visit('/form')
35
- @session.click_link_or_button(:'awe123')
36
+ @session.click_link_or_button(:awe123)
36
37
  expect(extract_results(@session)['first_name']).to eq('John')
37
38
  end
38
39
 
39
40
  context "with :exact option" do
40
- context "when `true`" do
41
+ context "when `false`" do
41
42
  it "clicks on approximately matching link" do
42
43
  @session.visit('/with_html')
43
- @session.click_link_or_button('abore', exact: false)
44
+ @session.click_link_or_button('abore', exact: false)
44
45
  expect(@session).to have_content('Bar')
45
46
  end
46
47
 
47
48
  it "clicks on approximately matching button" do
48
49
  @session.visit('/form')
49
- @session.click_link_or_button('awe')
50
+ @session.click_link_or_button('awe', exact: false)
50
51
  expect(extract_results(@session)['first_name']).to eq('John')
51
52
  end
52
53
  end
53
54
 
54
- context "when `false`" do
55
+ context "when `true`" do
55
56
  it "does not click on link which matches approximately" do
56
57
  @session.visit('/with_html')
57
58
  msg = "Unable to find visible link or button \"abore\""
58
59
  expect do
59
- @session.click_link_or_button('abore', exact: true)
60
+ @session.click_link_or_button('abore', exact: true)
60
61
  end.to raise_error(Capybara::ElementNotFound, msg)
61
62
  end
62
63
 
@@ -65,7 +66,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
65
66
  msg = "Unable to find visible link or button \"awe\""
66
67
 
67
68
  expect do
68
- @session.click_link_or_button('awe', exact: true)
69
+ @session.click_link_or_button('awe', exact: true)
69
70
  end.to raise_error(Capybara::ElementNotFound, msg)
70
71
  end
71
72
  end