capybara-mechanize 1.1.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
19
19
  def reset_host!
20
20
  @last_remote_uri = nil
21
21
  @last_request_remote = nil
22
+ @errored_remote_response = nil
22
23
  super
23
24
  end
24
25
 
@@ -71,7 +72,7 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
71
72
  end.map { |node| Capybara::Mechanize::Node.new(self, node) }
72
73
  end
73
74
 
74
- attr_reader :agent
75
+ attr_reader :agent, :errored_remote_response
75
76
 
76
77
  private
77
78
 
@@ -116,8 +117,13 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
116
117
  else
117
118
  @agent.send(method, url, attributes, headers)
118
119
  end
119
- rescue => e
120
- raise "Received the following error for a #{method.to_s.upcase} request to #{url}: '#{e.message}'"
120
+ @errored_remote_response = nil
121
+ rescue Mechanize::ResponseCodeError => e
122
+ @errored_remote_response = e.page
123
+
124
+ if Capybara.raise_server_errors
125
+ raise "Received the following error for a #{method.to_s.upcase} request to #{url}: '#{e.message}'"
126
+ end
121
127
  end
122
128
  @last_request_remote = true
123
129
  end
@@ -129,7 +135,11 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
129
135
  end
130
136
 
131
137
  def remote_response
132
- ResponseProxy.new(@agent.current_page) if @agent.current_page
138
+ if errored_remote_response
139
+ ResponseProxy.new(errored_remote_response)
140
+ elsif @agent.current_page
141
+ ResponseProxy.new(@agent.current_page)
142
+ end
133
143
  end
134
144
 
135
145
  def default_user_agent
@@ -4,7 +4,8 @@ class Capybara::Mechanize::Node < Capybara::RackTest::Node
4
4
  super
5
5
  elsif (tag_name == 'input' and %w(submit image).include?(type)) or
6
6
  ((tag_name == 'button') and type.nil? or type == "submit")
7
- Capybara::Mechanize::Form.new(driver, form).submit(self)
7
+ associated_form = form
8
+ Capybara::Mechanize::Form.new(driver, form).submit(self) if associated_form
8
9
  end
9
10
  end
10
11
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Mechanize
3
- VERSION = '1.1.0'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  require 'capybara/spec/test_app'
2
2
 
3
- class ExtendedTestApp < TestApp#< Sinatra::Base
3
+ class ExtendedTestApp < TestApp
4
4
  set :environment, :production # so we don't get debug info that makes our test pass!
5
5
  disable :protection
6
6
 
@@ -90,7 +90,6 @@ describe Capybara::Mechanize::Driver, 'local' do
90
90
  end
91
91
 
92
92
  context "with an app_host" do
93
-
94
93
  before do
95
94
  Capybara.app_host = 'http://www.remote.com'
96
95
  end
@@ -109,9 +108,22 @@ describe Capybara::Mechanize::Driver, 'local' do
109
108
  Capybara.default_host = 'www.local.com'
110
109
  end
111
110
 
112
- it "should allow local hosts to be set" do
113
- Capybara::Mechanize.local_hosts = ['subdomain.local.com']
114
- driver.should_not be_remote('http://subdomain.local.com')
111
+ after do
112
+ Capybara.default_host = CAPYBARA_DEFAULT_HOST
113
+ end
114
+
115
+ context "local hosts" do
116
+ before do
117
+ Capybara::Mechanize.local_hosts = ['subdomain.local.com']
118
+ end
119
+
120
+ after do
121
+ Capybara::Mechanize.local_hosts = nil
122
+ end
123
+
124
+ it "should allow local hosts to be set" do
125
+ driver.should_not be_remote('http://subdomain.local.com')
126
+ end
115
127
  end
116
128
 
117
129
  it "should treat urls with the same host names as local" do
@@ -123,7 +135,7 @@ describe Capybara::Mechanize::Driver, 'local' do
123
135
  end
124
136
 
125
137
  it "should treat relative paths as remote if the previous request was remote" do
126
- driver.visit(REMOTE_TEST_URL)
138
+ driver.visit(remote_test_url)
127
139
  driver.should be_remote('/some_relative_link')
128
140
  end
129
141
 
@@ -146,7 +158,7 @@ describe Capybara::Mechanize::Driver, 'local' do
146
158
  end
147
159
 
148
160
  it "should consider relative paths to be remote when the previous request was remote" do
149
- driver.visit("#{REMOTE_TEST_URL}/host")
161
+ driver.visit("#{remote_test_url}/host")
150
162
  driver.get('/host')
151
163
 
152
164
  should_be_a_remote_get
@@ -156,7 +168,7 @@ describe Capybara::Mechanize::Driver, 'local' do
156
168
  it "should always switch to the right context" do
157
169
  driver.visit('http://www.local.com/host')
158
170
  driver.get('/host')
159
- driver.get("#{REMOTE_TEST_URL}/host")
171
+ driver.get("#{remote_test_url}/host")
160
172
  driver.get('/host')
161
173
  driver.get('http://www.local.com/host')
162
174
 
@@ -165,28 +177,41 @@ describe Capybara::Mechanize::Driver, 'local' do
165
177
  end
166
178
 
167
179
  it "should follow redirects from local to remote" do
168
- driver.visit("http://www.local.com/redirect_to/#{REMOTE_TEST_URL}/host")
180
+ driver.visit("http://www.local.com/redirect_to/#{remote_test_url}/host")
169
181
  should_be_a_remote_get
170
182
  end
171
183
 
172
184
  it "should follow redirects from remote to local" do
173
- driver.visit("#{REMOTE_TEST_URL}/redirect_to/http://www.local.com/host")
185
+ driver.visit("#{remote_test_url}/redirect_to/http://www.local.com/host")
174
186
  should_be_a_local_get
175
187
  end
176
188
 
177
- after do
178
- Capybara.default_host = nil
189
+ it "passes the status code of remote calls back to be validated" do
190
+ quietly do
191
+ driver.visit(remote_test_url)
192
+ driver.get('/asdfafadfsdfs')
193
+ driver.response.status.should be >= 400
194
+ end
179
195
  end
180
196
 
181
- it "should raise a useful error for sites that return a 404, because it is probably a misconfiguration" do
182
- expect {
183
- driver.visit("http://iamreallysurethatthisdoesntexist.com/canttouchthis")
184
- }.to raise_error(%r{Received the following error for a GET request to http://iamreallysurethatthisdoesntexist.com/canttouchthis:})
197
+ context "when errors are set to true" do
198
+ it "raises an useful error because it is probably a misconfiguration" do
199
+ quietly do
200
+ original = Capybara.raise_server_errors
201
+
202
+ expect {
203
+ driver.visit(remote_test_url)
204
+ Capybara.raise_server_errors = true
205
+ driver.get('/asdfafadfsdfs')
206
+ }.to raise_error(%r{Received the following error for a GET request to /asdfafadfsdfs:})
207
+ Capybara.raise_server_errors = original
208
+ end
209
+ end
185
210
  end
186
211
  end
187
212
 
188
213
  it "should include the right host when remote" do
189
- driver.visit("#{REMOTE_TEST_URL}/host")
214
+ driver.visit("#{remote_test_url}/host")
190
215
  should_be_a_remote_get
191
216
  end
192
217
 
@@ -195,8 +220,12 @@ describe Capybara::Mechanize::Driver, 'local' do
195
220
  Capybara.default_host = 'http://www.local.com'
196
221
  end
197
222
 
223
+ after do
224
+ Capybara.default_host = CAPYBARA_DEFAULT_HOST
225
+ end
226
+
198
227
  it 'should reset remote host' do
199
- driver.visit("#{REMOTE_TEST_URL}/host")
228
+ driver.visit("#{remote_test_url}/host")
200
229
  should_be_a_remote_get
201
230
  driver.reset!
202
231
  driver.visit("/host")
@@ -205,11 +234,11 @@ describe Capybara::Mechanize::Driver, 'local' do
205
234
  end
206
235
 
207
236
  def should_be_a_remote_get
208
- driver.current_url.should include(REMOTE_TEST_URL)
237
+ driver.current_url.should include(remote_test_url)
209
238
  end
210
239
 
211
240
  def should_be_a_local_get
212
241
  driver.current_url.should include("www.local.com")
213
242
  end
214
- #
243
+
215
244
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Capybara::Mechanize::Driver, 'remote' do
4
4
  before do
5
- Capybara.app_host = REMOTE_TEST_URL
5
+ Capybara.app_host = remote_test_url
6
6
  end
7
7
 
8
8
  after do
@@ -13,32 +13,32 @@ describe Capybara::Mechanize::Driver, 'remote' do
13
13
 
14
14
  context "in remote mode" do
15
15
  it "should pass arguments through to a get request" do
16
- driver.visit("#{REMOTE_TEST_URL}/form/get", {:form => "success"})
16
+ driver.visit("#{remote_test_url}/form/get", {:form => "success"})
17
17
  driver.html.should include('success')
18
18
  end
19
19
 
20
20
  it "should pass arguments through to a post request" do
21
- driver.post("#{REMOTE_TEST_URL}/form", {:form => "success"})
21
+ driver.post("#{remote_test_url}/form", {:form => "success"})
22
22
  driver.html.should include('success')
23
23
  end
24
24
 
25
25
  describe "redirect" do
26
26
  it "should handle redirects with http-params" do
27
- driver.visit "#{REMOTE_TEST_URL}/redirect_with_http_param"
27
+ driver.visit "#{remote_test_url}/redirect_with_http_param"
28
28
  driver.html.should include('correct redirect')
29
29
  end
30
30
  end
31
31
 
32
32
  context "for a post request" do
33
33
  it 'transforms nested map in post data' do
34
- driver.post("#{REMOTE_TEST_URL}/form", {:form => {:key => 'value'}})
34
+ driver.post("#{remote_test_url}/form", {:form => {:key => 'value'}})
35
35
  driver.html.should include(':key=>"value"')
36
36
  end
37
37
  end
38
38
 
39
39
  context 'process remote request' do
40
40
  it 'transforms nested map in post data' do
41
- driver.submit(:post, "#{REMOTE_TEST_URL}/form", {:form => {:key => 'value'}})
41
+ driver.submit(:post, "#{remote_test_url}/form", {:form => {:key => 'value'}})
42
42
  driver.html.should include(':key=>"value"')
43
43
  end
44
44
  end
@@ -4,13 +4,15 @@ module TestSessions
4
4
  Mechanize = Capybara::Session.new(:mechanize, TestApp)
5
5
  end
6
6
 
7
- Capybara::SpecHelper.run_specs TestSessions::Mechanize, "Mechanize", :skip => [
7
+ Capybara::SpecHelper.run_specs TestSessions::Mechanize, "Mechanize", :capybara_skip => [
8
8
  :js,
9
9
  :screenshot,
10
10
  :frames,
11
11
  :windows,
12
12
  :server,
13
- :hover
13
+ :hover,
14
+ :modals,
15
+ :about_scheme
14
16
  ]
15
17
 
16
18
  describe Capybara::Session do
@@ -21,6 +23,10 @@ describe Capybara::Session do
21
23
  Capybara.default_host = 'http://www.local.com'
22
24
  end
23
25
 
26
+ after do
27
+ Capybara.default_host = CAPYBARA_DEFAULT_HOST
28
+ end
29
+
24
30
  describe '#driver' do
25
31
  it "should be a mechanize driver" do
26
32
  session.driver.should be_an_instance_of(Capybara::Mechanize::Driver)
@@ -71,31 +77,31 @@ describe Capybara::Session do
71
77
  end
72
78
 
73
79
  it "should use the last remote url when following relative links" do
74
- session.visit("#{REMOTE_TEST_URL}/relative_link_to_host")
80
+ session.visit("#{remote_test_url}/relative_link_to_host")
75
81
  session.click_link "host"
76
- session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/host, method get")
82
+ session.body.should include("Current host is #{remote_test_url}/request_info/host, method get")
77
83
  end
78
84
 
79
85
  it "should use the last remote url when submitting a form with a relative action" do
80
- session.visit("#{REMOTE_TEST_URL}/form_with_relative_action_to_host")
86
+ session.visit("#{remote_test_url}/form_with_relative_action_to_host")
81
87
  session.click_button "submit"
82
- session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/host, method post")
88
+ session.body.should include("Current host is #{remote_test_url}/request_info/host, method post")
83
89
  end
84
90
 
85
91
  it "should use the last url when submitting a form with no action" do
86
- session.visit("#{REMOTE_TEST_URL}/request_info/form_with_no_action")
92
+ session.visit("#{remote_test_url}/request_info/form_with_no_action")
87
93
  session.click_button "submit"
88
- session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/form_with_no_action, method post")
94
+ session.body.should include("Current host is #{remote_test_url}/request_info/form_with_no_action, method post")
89
95
  end
90
96
 
91
97
  it "should send correct user agent" do
92
- session.visit("#{REMOTE_TEST_URL}/request_info/user_agent")
98
+ session.visit("#{remote_test_url}/request_info/user_agent")
93
99
  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")
94
100
  end
95
101
 
96
102
  context 'form referer when switching from local to remote' do
97
103
  it 'sends the referer' do
98
- session.visit "/form_posts_to/#{REMOTE_TEST_URL}/get_referer"
104
+ session.visit "/form_posts_to/#{remote_test_url}/get_referer"
99
105
  session.click_button 'submit'
100
106
  session.body.should include 'Got referer'
101
107
  end
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  shared_context "remote tests" do
8
8
  before do
9
- Capybara.app_host = REMOTE_TEST_URL
9
+ Capybara.app_host = remote_test_url
10
10
  end
11
11
 
12
12
  after do
@@ -14,13 +14,15 @@ shared_context "remote tests" do
14
14
  end
15
15
  end
16
16
 
17
- session_describe = Capybara::SpecHelper.run_specs TestSessions::Mechanize, "Mechanize", :skip => [
17
+ session_describe = Capybara::SpecHelper.run_specs TestSessions::Mechanize, "Mechanize", :capybara_skip => [
18
18
  :js,
19
19
  :screenshot,
20
20
  :frames,
21
21
  :windows,
22
22
  :server,
23
- :hover
23
+ :hover,
24
+ :modals,
25
+ :about_scheme
24
26
  ]
25
27
 
26
28
  session_describe.include_context("remote tests")
@@ -17,12 +17,18 @@ RSpec.configure do |config|
17
17
  # Used with DisableExternalTests
18
18
  config.filter_run_excluding :external_test_disabled
19
19
 
20
+ config.include RemoteTestUrl
21
+ config.extend RemoteTestUrl
22
+ config.include Capybara::SpecHelper
23
+
20
24
  config.after do
21
25
  Capybara::Mechanize.local_hosts = nil
22
26
  end
23
27
 
24
28
  Capybara::SpecHelper.configure(config)
29
+
30
+ config.order = "random"
31
+
32
+ CAPYBARA_DEFAULT_HOST = Capybara.default_host
25
33
  end
26
34
 
27
- setup = ExtendedTestAppSetup.new.boot
28
- REMOTE_TEST_URL = setup.remote_test_url
@@ -9,6 +9,7 @@ class ExtendedTestAppSetup
9
9
  def boot
10
10
  boot_test_app
11
11
  boot_remote_app
12
+ Capybara.raise_server_errors = false
12
13
 
13
14
  self
14
15
  end
@@ -0,0 +1,5 @@
1
+ module RemoteTestUrl
2
+ def remote_test_url
3
+ ExtendedTestAppSetup.new.boot.remote_test_url
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-29 00:00:00.000000000 Z
12
+ date: 2014-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '2.7'
21
+ version: 2.7.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '2.7'
29
+ version: 2.7.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: capybara
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.1.0
37
+ version: 2.4.4
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.1.0
45
+ version: 2.4.4
46
46
  description: RackTest driver for Capybara, but with remote request support thanks
47
47
  to mechanize
48
48
  email: jeroen@jeevidee.nl
@@ -65,6 +65,7 @@ files:
65
65
  - spec/spec_helper.rb
66
66
  - spec/support/disable_external_tests.rb
67
67
  - spec/support/extended_test_app_setup.rb
68
+ - spec/support/remote_test_url.rb
68
69
  - README.mdown
69
70
  homepage: https://github.com/jeroenvandijk/capybara-mechanize
70
71
  licenses: []
@@ -79,6 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
80
  - - ! '>='
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
83
+ segments:
84
+ - 0
85
+ hash: 1895227021431628826
82
86
  required_rubygems_version: !ruby/object:Gem::Requirement
83
87
  none: false
84
88
  requirements:
@@ -87,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
91
  version: '0'
88
92
  requirements: []
89
93
  rubyforge_project:
90
- rubygems_version: 1.8.24
94
+ rubygems_version: 1.8.23
91
95
  signing_key:
92
96
  specification_version: 3
93
97
  summary: RackTest driver for Capybara with remote request support