capybara-mechanize 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.mdown
CHANGED
@@ -28,6 +28,14 @@ The following scenario will then be using the Mechanize driver
|
|
28
28
|
@mechanize
|
29
29
|
Scenario: do something remote
|
30
30
|
When I click the remote link
|
31
|
+
|
32
|
+
### Remote testing
|
33
|
+
|
34
|
+
When you want to use this driver to test a remote application. You have to set the app_host:
|
35
|
+
|
36
|
+
Capybara.app_host = "http://www.yourapp.com"
|
37
|
+
|
38
|
+
Note that I haven't tested this case for my self yet. The Capybara tests pass for this situation though so it should work! Please provide me with feedback if it doesn't.
|
31
39
|
|
32
40
|
Todo
|
33
41
|
----
|
@@ -5,15 +5,39 @@ class Capybara::Driver::Mechanize < Capybara::Driver::RackTest
|
|
5
5
|
def initialize(*args)
|
6
6
|
super
|
7
7
|
@agent = ::Mechanize.new
|
8
|
+
@agent.redirect_ok = false
|
8
9
|
end
|
9
10
|
|
10
11
|
def visit(url)
|
11
12
|
get url
|
12
13
|
end
|
13
14
|
|
15
|
+
def cleanup!
|
16
|
+
@agent.cookie_jar.clear!
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_url
|
21
|
+
(response_proxy && response_proxy.current_url) || super
|
22
|
+
end
|
23
|
+
|
14
24
|
def response
|
15
25
|
response_proxy || super
|
16
26
|
end
|
27
|
+
|
28
|
+
# TODO see how this can be cleaned up
|
29
|
+
def follow_redirect!
|
30
|
+
unless response.redirect?
|
31
|
+
raise "Last response was not a redirect. Cannot follow_redirect!"
|
32
|
+
end
|
33
|
+
|
34
|
+
if response.respond_to?(:page)
|
35
|
+
location = response.page.response['Location']
|
36
|
+
else
|
37
|
+
location = response['Location']
|
38
|
+
end
|
39
|
+
get(location)
|
40
|
+
end
|
17
41
|
|
18
42
|
def get(url, params = {}, headers = {})
|
19
43
|
process_remote_request(:get, url) || super
|
@@ -38,6 +62,7 @@ class Capybara::Driver::Mechanize < Capybara::Driver::RackTest
|
|
38
62
|
|
39
63
|
def process_remote_request(method, url, *options)
|
40
64
|
if remote?(url)
|
65
|
+
url = File.join((Capybara.app_host || Capybara.default_host), url) if URI.parse(url).host.nil?
|
41
66
|
reset_cache
|
42
67
|
@agent.send *( [method, url] + options)
|
43
68
|
follow_redirects!
|
@@ -50,16 +75,30 @@ class Capybara::Driver::Mechanize < Capybara::Driver::RackTest
|
|
50
75
|
end
|
51
76
|
|
52
77
|
class ResponseProxy
|
78
|
+
extend Forwardable
|
79
|
+
|
80
|
+
def_delegator :page, :body
|
81
|
+
|
82
|
+
attr_reader :page
|
83
|
+
|
53
84
|
def initialize(page)
|
54
85
|
@page = page
|
55
86
|
end
|
56
87
|
|
57
|
-
def
|
58
|
-
|
88
|
+
def current_url
|
89
|
+
page.uri.to_s
|
59
90
|
end
|
60
91
|
|
61
|
-
def
|
62
|
-
|
92
|
+
def headers
|
93
|
+
page.response
|
94
|
+
end
|
95
|
+
|
96
|
+
def status
|
97
|
+
page.code.to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
def redirect?
|
101
|
+
[301, 302].include?(status)
|
63
102
|
end
|
64
103
|
|
65
104
|
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Capybara::Driver::Mechanize do
|
4
|
+
before(:each) do
|
5
|
+
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:each) do
|
9
|
+
Capybara.app_host = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
@driver = Capybara::Driver::Mechanize.new(TestApp)
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like "driver"
|
17
|
+
it_should_behave_like "driver with header support"
|
18
|
+
it_should_behave_like "driver with status code support"
|
19
|
+
it_should_behave_like "driver with cookies support"
|
20
|
+
|
21
|
+
# Pending:
|
22
|
+
# it_should_behave_like "driver with infinite redirect detection"
|
23
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-mechanize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeroen van Dijk
|
@@ -78,7 +78,8 @@ files:
|
|
78
78
|
- lib/capybara/driver/mechanize.rb
|
79
79
|
- lib/capybara/mechanize/cucumber.rb
|
80
80
|
- lib/capybara/mechanize.rb
|
81
|
-
- spec/driver/
|
81
|
+
- spec/driver/mechanize_driver_spec.rb
|
82
|
+
- spec/driver/remote_mechanize_driver_spec.rb
|
82
83
|
- spec/session/mechanize_spec.rb
|
83
84
|
- spec/spec.opts
|
84
85
|
- spec/spec_helper.rb
|