capybara-mechanize 1.10.1 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,104 +1,106 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Capybara::Mechanize::Driver, 'local' do
4
6
  let(:driver) { Capybara::Mechanize::Driver.new(ExtendedTestApp) }
5
7
 
6
- describe "#configure" do
7
- it "allows extended configuration of the agent" do
8
- ::Mechanize.any_instance.should_receive(:foo=).with("test")
8
+ describe '#configure' do
9
+ it 'allows extended configuration of the agent' do
10
+ expect_any_instance_of(::Mechanize).to receive(:foo=).with('test')
9
11
  driver.configure do |agent|
10
- agent.foo = "test"
12
+ agent.foo = 'test'
11
13
  end
12
14
  end
13
15
  end
14
16
 
15
17
  describe ':headers option' do
16
18
  it 'should always set headers' do
17
- driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
19
+ driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
18
20
  driver.visit('/get_header')
19
- driver.html.should include('foobar')
21
+ expect(driver.html).to include('foobar')
20
22
  end
21
23
 
22
24
  it 'should keep headers on link clicks' do
23
- driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
25
+ driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
24
26
  driver.visit('/header_links')
25
27
  driver.find_xpath('.//a').first.click
26
- driver.html.should include('foobar')
28
+ expect(driver.html).to include('foobar')
27
29
  end
28
30
 
29
31
  it 'should keep headers on form submit' do
30
- driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
32
+ driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
31
33
  driver.visit('/header_links')
32
34
  driver.find_xpath('.//input').first.click
33
- driver.html.should include('foobar')
35
+ expect(driver.html).to include('foobar')
34
36
  end
35
37
 
36
38
  it 'should keep headers on redirects' do
37
- driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
39
+ driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
38
40
  driver.visit('/get_header_via_redirect')
39
- driver.html.should include('foobar')
41
+ expect(driver.html).to include('foobar')
40
42
  end
41
43
  end
42
44
 
43
45
  describe ':follow_redirects option' do
44
- it "defaults to following redirects" do
46
+ it 'defaults to following redirects' do
45
47
  driver = Capybara::RackTest::Driver.new(TestApp)
46
48
 
47
49
  driver.visit('/redirect')
48
- driver.response.header['Location'].should be_nil
49
- driver.browser.current_url.should match %r{/landed$}
50
+ expect(driver.response.header['Location']).to be_nil
51
+ expect(driver.browser.current_url).to match %r{/landed$}
50
52
  end
51
53
 
52
- it "is possible to not follow redirects" do
53
- driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
54
+ it 'is possible to not follow redirects' do
55
+ driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
54
56
 
55
57
  driver.visit('/redirect')
56
- driver.response.header['Location'].should match %r{/redirect_again$}
57
- driver.browser.current_url.should match %r{/redirect$}
58
+ expect(driver.response.header['Location']).to match %r{/redirect_again$}
59
+ expect(driver.browser.current_url).to match %r{/redirect$}
58
60
  end
59
61
  end
60
62
 
61
63
  describe ':redirect_limit option' do
62
- context "with default redirect limit" do
64
+ context 'with default redirect limit' do
63
65
  let(:driver) { Capybara::RackTest::Driver.new(TestApp) }
64
66
 
65
- it "should follow 5 redirects" do
66
- driver.visit("/redirect/5/times")
67
- driver.html.should include('redirection complete')
67
+ it 'should follow 5 redirects' do
68
+ driver.visit('/redirect/5/times')
69
+ expect(driver.html).to include('redirection complete')
68
70
  end
69
71
 
70
- it "should not follow more than 6 redirects" do
72
+ it 'should not follow more than 6 redirects' do
71
73
  expect do
72
- driver.visit("/redirect/6/times")
74
+ driver.visit('/redirect/6/times')
73
75
  end.to raise_error(Capybara::InfiniteRedirectError)
74
76
  end
75
77
  end
76
78
 
77
- context "with 21 redirect limit" do
78
- let(:driver) { Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21) }
79
+ context 'with 21 redirect limit' do
80
+ let(:driver) { Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21) }
79
81
 
80
- it "should follow 21 redirects" do
81
- driver.visit("/redirect/21/times")
82
- driver.html.should include('redirection complete')
82
+ it 'should follow 21 redirects' do
83
+ driver.visit('/redirect/21/times')
84
+ expect(driver.html).to include('redirection complete')
83
85
  end
84
86
 
85
- it "should not follow more than 21 redirects" do
87
+ it 'should not follow more than 21 redirects' do
86
88
  expect do
87
- driver.visit("/redirect/22/times")
89
+ driver.visit('/redirect/22/times')
88
90
  end.to raise_error(Capybara::InfiniteRedirectError)
89
91
  end
90
92
  end
91
93
  end
92
94
 
93
- it "should default to local mode for relative paths" do
94
- driver.should_not be_remote('/')
95
+ it 'should default to local mode for relative paths' do
96
+ expect(driver).not_to be_remote('/')
95
97
  end
96
98
 
97
- it "should default to local mode for the default host" do
98
- driver.should_not be_remote('http://www.example.com')
99
+ it 'should default to local mode for the default host' do
100
+ expect(driver).not_to be_remote('http://www.example.com')
99
101
  end
100
102
 
101
- context "with an app_host" do
103
+ context 'with an app_host' do
102
104
  before do
103
105
  Capybara.app_host = 'http://www.remote.com'
104
106
  end
@@ -107,12 +109,12 @@ describe Capybara::Mechanize::Driver, 'local' do
107
109
  Capybara.app_host = nil
108
110
  end
109
111
 
110
- it "should treat urls as remote" do
111
- driver.should be_remote('http://www.remote.com')
112
+ it 'should treat urls as remote' do
113
+ expect(driver).to be_remote('http://www.remote.com')
112
114
  end
113
115
  end
114
116
 
115
- context "with a default url, no app host" do
117
+ context 'with a default url, no app host' do
116
118
  before do
117
119
  Capybara.default_host = 'http://www.local.com'
118
120
  end
@@ -121,7 +123,7 @@ describe Capybara::Mechanize::Driver, 'local' do
121
123
  Capybara.default_host = CAPYBARA_DEFAULT_HOST
122
124
  end
123
125
 
124
- context "local hosts" do
126
+ context 'local hosts' do
125
127
  before do
126
128
  Capybara::Mechanize.local_hosts = ['subdomain.local.com']
127
129
  end
@@ -130,51 +132,51 @@ describe Capybara::Mechanize::Driver, 'local' do
130
132
  Capybara::Mechanize.local_hosts = nil
131
133
  end
132
134
 
133
- it "should allow local hosts to be set" do
134
- driver.should_not be_remote('http://subdomain.local.com')
135
+ it 'should allow local hosts to be set' do
136
+ expect(driver).not_to be_remote('http://subdomain.local.com')
135
137
  end
136
138
  end
137
139
 
138
- it "should treat urls with the same host names as local" do
139
- driver.should_not be_remote('http://www.local.com')
140
+ it 'should treat urls with the same host names as local' do
141
+ expect(driver).not_to be_remote('http://www.local.com')
140
142
  end
141
143
 
142
- it "should treat other urls as remote" do
143
- driver.should be_remote('http://www.remote.com')
144
+ it 'should treat other urls as remote' do
145
+ expect(driver).to be_remote('http://www.remote.com')
144
146
  end
145
147
 
146
- it "should treat relative paths as remote if the previous request was remote" do
148
+ it 'should treat relative paths as remote if the previous request was remote' do
147
149
  driver.visit(remote_test_url)
148
- driver.should be_remote('/some_relative_link')
150
+ expect(driver).to be_remote('/some_relative_link')
149
151
  end
150
152
 
151
- it "should treat relative paths as local if the previous request was local" do
153
+ it 'should treat relative paths as local if the previous request was local' do
152
154
  driver.visit('http://www.local.com')
153
- driver.should_not be_remote('/some_relative_link')
155
+ expect(driver).not_to be_remote('/some_relative_link')
154
156
  end
155
157
 
156
- it "should receive the right host" do
158
+ it 'should receive the right host' do
157
159
  driver.visit('http://www.local.com/host')
158
160
  should_be_a_local_get
159
161
  end
160
162
 
161
- it "should consider relative paths to be local when the previous request was local" do
163
+ it 'should consider relative paths to be local when the previous request was local' do
162
164
  driver.visit('http://www.local.com/host')
163
165
  driver.visit('/host')
164
166
 
165
167
  should_be_a_local_get
166
- driver.should_not be_remote('/first_local')
168
+ expect(driver).not_to be_remote('/first_local')
167
169
  end
168
170
 
169
- it "should consider relative paths to be remote when the previous request was remote" do
171
+ it 'should consider relative paths to be remote when the previous request was remote' do
170
172
  driver.visit("#{remote_test_url}/host")
171
173
  driver.get('/host')
172
174
 
173
175
  should_be_a_remote_get
174
- driver.should be_remote('/second_remote')
176
+ expect(driver).to be_remote('/second_remote')
175
177
  end
176
178
 
177
- it "should always switch to the right context" do
179
+ it 'should always switch to the right context' do
178
180
  driver.visit('http://www.local.com/host')
179
181
  driver.get('/host')
180
182
  driver.get("#{remote_test_url}/host")
@@ -182,44 +184,44 @@ describe Capybara::Mechanize::Driver, 'local' do
182
184
  driver.get('http://www.local.com/host')
183
185
 
184
186
  should_be_a_local_get
185
- driver.should_not be_remote('/second_local')
187
+ expect(driver).not_to be_remote('/second_local')
186
188
  end
187
189
 
188
- it "should follow redirects from local to remote" do
190
+ it 'should follow redirects from local to remote' do
189
191
  driver.visit("http://www.local.com/redirect_to/#{remote_test_url}/host")
190
192
  should_be_a_remote_get
191
193
  end
192
194
 
193
- it "should follow redirects from remote to local" do
195
+ it 'should follow redirects from remote to local' do
194
196
  driver.visit("#{remote_test_url}/redirect_to/http://www.local.com/host")
195
197
  should_be_a_local_get
196
198
  end
197
199
 
198
- it "passes the status code of remote calls back to be validated" do
200
+ it 'passes the status code of remote calls back to be validated' do
199
201
  quietly do
200
202
  driver.visit(remote_test_url)
201
203
  driver.get('/asdfafadfsdfs')
202
- driver.response.status.should be >= 400
204
+ expect(driver.response.status).to be >= 400
203
205
  end
204
206
  end
205
207
 
206
- context "when errors are set to true" do
207
- it "raises an useful error because it is probably a misconfiguration" do
208
+ context 'when errors are set to true' do
209
+ it 'raises an useful error because it is probably a misconfiguration' do
208
210
  quietly do
209
211
  original = Capybara.raise_server_errors
210
212
 
211
- expect {
213
+ expect do
212
214
  driver.visit(remote_test_url)
213
215
  Capybara.raise_server_errors = true
214
216
  driver.get('/asdfafadfsdfs')
215
- }.to raise_error(%r{Received the following error for a GET request to /asdfafadfsdfs:})
217
+ end.to raise_error(%r{Received the following error for a GET request to /asdfafadfsdfs:})
216
218
  Capybara.raise_server_errors = original
217
219
  end
218
220
  end
219
221
  end
220
222
  end
221
223
 
222
- it "should include the right host when remote" do
224
+ it 'should include the right host when remote' do
223
225
  driver.visit("#{remote_test_url}/host")
224
226
  should_be_a_remote_get
225
227
  end
@@ -237,17 +239,16 @@ describe Capybara::Mechanize::Driver, 'local' do
237
239
  driver.visit("#{remote_test_url}/host")
238
240
  should_be_a_remote_get
239
241
  driver.reset!
240
- driver.visit("/host")
242
+ driver.visit('/host')
241
243
  should_be_a_local_get
242
244
  end
243
245
  end
244
246
 
245
247
  def should_be_a_remote_get
246
- driver.current_url.should include(remote_test_url)
248
+ expect(driver.current_url).to include(remote_test_url)
247
249
  end
248
250
 
249
251
  def should_be_a_local_get
250
- driver.current_url.should include("www.local.com")
252
+ expect(driver.current_url).to include('www.local.com')
251
253
  end
252
-
253
254
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Capybara::Mechanize::Driver, 'remote' do
@@ -11,35 +13,35 @@ describe Capybara::Mechanize::Driver, 'remote' do
11
13
 
12
14
  let(:driver) { Capybara::Mechanize::Driver.new(ExtendedTestApp) }
13
15
 
14
- context "in remote mode" do
15
- it "should pass arguments through to a get request" do
16
- driver.visit("#{remote_test_url}/form/get", {:form => "success"})
17
- driver.html.should include('success')
16
+ context 'in remote mode' do
17
+ it 'should pass arguments through to a get request' do
18
+ driver.visit("#{remote_test_url}/form/get", form: { value: 'success' })
19
+ expect(driver.html).to include('success')
18
20
  end
19
21
 
20
- it "should pass arguments through to a post request" do
21
- driver.post("#{remote_test_url}/form", {:form => "success"})
22
- driver.html.should include('success')
22
+ it 'should pass arguments through to a post request' do
23
+ driver.post("#{remote_test_url}/form", form: { value: 'success' })
24
+ expect(driver.html).to include('success')
23
25
  end
24
26
 
25
- describe "redirect" do
26
- it "should handle redirects with http-params" do
27
+ describe 'redirect' do
28
+ it 'should handle redirects with http-params' do
27
29
  driver.visit "#{remote_test_url}/redirect_with_http_param"
28
- driver.html.should include('correct redirect')
30
+ expect(driver.html).to include('correct redirect')
29
31
  end
30
32
  end
31
33
 
32
- context "for a post request" do
34
+ context 'for a post request' do
33
35
  it 'transforms nested map in post data' do
34
- driver.post("#{remote_test_url}/form", {:form => {:key => 'value'}})
35
- driver.html.should match(/:key=>"value"|key: value/)
36
+ driver.post("#{remote_test_url}/form", form: { key: 'value' })
37
+ expect(driver.html).to match(/:key=>"value"|key: value/)
36
38
  end
37
39
  end
38
40
 
39
41
  context 'process remote request' do
40
42
  it 'transforms nested map in post data' do
41
- driver.submit(:post, "#{remote_test_url}/form", {:form => {:key => 'value'}})
42
- driver.html.should match(/:key=>"value"|key: value/)
43
+ driver.submit(:post, "#{remote_test_url}/form", form: { key: 'value' })
44
+ expect(driver.html).to match(/:key=>"value"|key: value/)
43
45
  end
44
46
  end
45
47
  end
@@ -1,21 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module TestSessions
4
6
  Mechanize = Capybara::Session.new(:mechanize, TestApp)
5
7
  end
6
8
 
7
- Capybara::SpecHelper.run_specs TestSessions::Mechanize, "Mechanize", :capybara_skip => [
8
- :js,
9
- :screenshot,
10
- :frames,
11
- :windows,
12
- :server,
13
- :hover,
14
- :modals,
15
- :about_scheme,
16
- :send_keys
9
+ skipped_tests = %i[
10
+ about_scheme
11
+ active_element
12
+ css
13
+ download
14
+ frames
15
+ hover
16
+ html_validation
17
+ js
18
+ modals
19
+ screenshot
20
+ scroll
21
+ send_keys
22
+ server
23
+ shadow_dom
24
+ spatial
25
+ windows
17
26
  ]
18
27
 
28
+ Capybara::SpecHelper.run_specs(TestSessions::Mechanize, 'Mechanize', capybara_skip: skipped_tests) do |example|
29
+ case example.metadata[:full_description]
30
+ when /has_css\? should support case insensitive :class and :id options/
31
+ skip "Nokogiri doesn't support case insensitive CSS attribute matchers"
32
+ end
33
+ end
34
+
19
35
  describe Capybara::Session do
20
36
  context 'with mechanize driver' do
21
37
  let(:session) { Capybara::Session.new(:mechanize, ExtendedTestApp) }
@@ -29,37 +45,37 @@ describe Capybara::Session do
29
45
  end
30
46
 
31
47
  describe '#driver' do
32
- it "should be a mechanize driver" do
33
- session.driver.should be_an_instance_of(Capybara::Mechanize::Driver)
48
+ it 'should be a mechanize driver' do
49
+ expect(session.driver).to be_an_instance_of(Capybara::Mechanize::Driver)
34
50
  end
35
51
  end
36
52
 
37
53
  describe '#mode' do
38
- it "should remember the mode" do
39
- session.mode.should == :mechanize
54
+ it 'should remember the mode' do
55
+ expect(session.mode).to eq(:mechanize)
40
56
  end
41
57
  end
42
58
 
43
59
  describe '#click_link' do
44
- it "should use data-method if option is true" do
60
+ it 'should use data-method if option is true' do
45
61
  session.driver.options[:respect_data_method] = true
46
- session.visit "/with_html"
47
- session.click_link "A link with data-method"
48
- session.html.should include('The requested object was deleted')
62
+ session.visit '/with_html'
63
+ session.click_link 'A link with data-method'
64
+ expect(session.html).to include('The requested object was deleted')
49
65
  end
50
66
 
51
- it "should not use data-method if option is false" do
67
+ it 'should not use data-method if option is false' do
52
68
  session.driver.options[:respect_data_method] = false
53
- session.visit "/with_html"
54
- session.click_link "A link with data-method"
55
- session.html.should include('Not deleted')
69
+ session.visit '/with_html'
70
+ session.click_link 'A link with data-method'
71
+ expect(session.html).to include('Not deleted')
56
72
  end
57
73
 
58
74
  it "should use data-method if available even if it's capitalized" do
59
75
  session.driver.options[:respect_data_method] = true
60
- session.visit "/with_html"
61
- session.click_link "A link with capitalized data-method"
62
- session.html.should include('The requested object was deleted')
76
+ session.visit '/with_html'
77
+ session.click_link 'A link with capitalized data-method'
78
+ expect(session.html).to include('The requested object was deleted')
63
79
  end
64
80
 
65
81
  after do
@@ -67,44 +83,44 @@ describe Capybara::Session do
67
83
  end
68
84
  end
69
85
 
70
- describe "#attach_file" do
71
- context "with multipart form" do
72
- it "should submit an empty form-data section if no file is submitted" do
73
- session.visit("/form")
74
- session.click_button("Upload Empty")
75
- session.html.should include('Successfully ignored empty file field.')
86
+ describe '#attach_file' do
87
+ context 'with multipart form' do
88
+ it 'should submit an empty form-data section if no file is submitted' do
89
+ session.visit('/form')
90
+ session.click_button('Upload Empty')
91
+ expect(session.html).to include('Successfully ignored empty file field.')
76
92
  end
77
93
  end
78
94
  end
79
95
 
80
- it "should use the last remote url when following relative links" do
96
+ it 'should use the last remote url when following relative links' do
81
97
  session.visit("#{remote_test_url}/relative_link_to_host")
82
- session.click_link "host"
83
- session.body.should include("Current host is #{remote_test_url}/request_info/host, method get")
98
+ session.click_link 'host'
99
+ expect(session.body).to include("Current host is #{remote_test_url}/request_info/host, method get")
84
100
  end
85
101
 
86
- it "should use the last remote url when submitting a form with a relative action" do
102
+ it 'should use the last remote url when submitting a form with a relative action' do
87
103
  session.visit("#{remote_test_url}/form_with_relative_action_to_host")
88
- session.click_button "submit"
89
- session.body.should include("Current host is #{remote_test_url}/request_info/host, method post")
104
+ session.click_button 'submit'
105
+ expect(session.body).to include("Current host is #{remote_test_url}/request_info/host, method post")
90
106
  end
91
107
 
92
- it "should use the last url when submitting a form with no action" do
108
+ it 'should use the last url when submitting a form with no action' do
93
109
  session.visit("#{remote_test_url}/request_info/form_with_no_action")
94
- session.click_button "submit"
95
- session.body.should include("Current host is #{remote_test_url}/request_info/form_with_no_action, method post")
110
+ session.click_button 'submit'
111
+ expect(session.body).to include("Current host is #{remote_test_url}/request_info/form_with_no_action, method post")
96
112
  end
97
113
 
98
- it "should send correct user agent" do
114
+ it 'should send correct user agent' do
99
115
  session.visit("#{remote_test_url}/request_info/user_agent")
100
- session.body.should include("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.853.0 Safari/535.2")
116
+ expect(session.body).to include('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.853.0 Safari/535.2')
101
117
  end
102
118
 
103
119
  context 'form referer when switching from local to remote' do
104
120
  it 'sends the referer' do
105
121
  session.visit "/form_posts_to/#{remote_test_url}/get_referer"
106
122
  session.click_button 'submit'
107
- session.body.should include 'Got referer'
123
+ expect(session.body).to include 'Got referer'
108
124
  end
109
125
  end
110
126
  end