bbc-capybara-mechanize-with-proxy 0.3.0.rc0

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 ADDED
@@ -0,0 +1,89 @@
1
+ Capybara-mechanize
2
+ ==================
3
+
4
+ This gems makes it possible to use Capybara for (partially) remote testing. It inherits most functionality from the RackTest driver and only uses [Mechanize](http://github.com/tenderlove/mechanize) for remote requests.
5
+
6
+ It is currently in use to test the integration between a Rails application and Twitter authorization and sharing.
7
+
8
+ This gem is a [Capybara](http://github.com/jnicklas/capybara) extension. I have been inspired by the Capybara driver and some earlier efforts for a Mechanize driver.
9
+
10
+ Thanks to [Pinkelstar](http://www.pinkelstar.com) for giving me the time and the need to develop this gem.
11
+
12
+ ### Installation
13
+
14
+ gem install capybara-mechanize
15
+
16
+ ### Usage without Cucumber
17
+
18
+ require 'capybara/mechanize'
19
+
20
+ ### Usage with Cucumber and tags
21
+
22
+ A @mechanize tag is added to your hooks when you add the following line to your env.rb
23
+
24
+ require 'capybara/mechanize/cucumber'
25
+
26
+ The following scenario will then be using the Mechanize driver
27
+
28
+ @mechanize
29
+ Scenario: do something remote
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.
39
+
40
+ ### Mechanize using proxy
41
+
42
+ If you are behind a proxy, you can specify an PROXY=ON ENV variable on the command line and setup mechanize to use proxy or not as below:
43
+
44
+ Capybara.register_driver :mechanize do |app|
45
+ Capybara.app_host = "http://www.yourapp.com"
46
+ if ENV['PROXY'] == 'ON'
47
+ Capybara::Mechanize::Driver.new(app,{:proxy =>"http://yourproxy.com"})
48
+ else
49
+ Capybara::Mechanize::Driver.new(app)
50
+ end
51
+ end
52
+
53
+ ## Running tests
54
+
55
+ Until this library is merged with capybara there needs to be local app and you need to add the following to your host file:
56
+
57
+ 127.0.0.1 capybara-testapp.heroku.com
58
+
59
+ Run bundler
60
+
61
+ bundle install
62
+
63
+ Run the app with the following line:
64
+
65
+ bundle exec ruby -rrubygems lib/capybara/spec/extended_test_app.rb
66
+
67
+ Then you are ready to run the test like so
68
+
69
+ rake spec
70
+
71
+ Todo
72
+ ----
73
+ * Make the last 12 failing remote session spec pass, see remote_mechanize_spec and uncomment one line there to see them fail
74
+ * Test this driver with non-rack/non-ruby projects
75
+
76
+ Note on Patches/Pull Requests
77
+ -----------------------------
78
+
79
+ * Fork the project.
80
+ * Make your feature addition or bug fix.
81
+ * Add tests for it. This is important so I don't break it in a
82
+ future version unintentionally.
83
+ * Commit, do not mess with rakefile, version, or history.
84
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
85
+ * Send me a pull request. Bonus points for topic branches.
86
+
87
+ Copyright
88
+ ---------
89
+ Copyright (c) 2010 Jeroen van Dijk. See LICENSE for details.
@@ -0,0 +1,235 @@
1
+ require 'capybara/rack_test/driver'
2
+ require 'mechanize'
3
+
4
+ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
5
+ extend Forwardable
6
+
7
+ def_delegator :agent, :scheme_handlers
8
+ def_delegator :agent, :scheme_handlers=
9
+
10
+ def initialize(app, options)
11
+ @agent = ::Mechanize.new
12
+ @agent.redirect_ok = false
13
+ if !options.empty?
14
+ if options[:proxy] && !options[:proxy].empty?
15
+ proxy = nil
16
+ begin
17
+ proxy = URI.parse(options[:proxy])
18
+ rescue URI::InvalidURIError => e
19
+ raise "You have entered an invalid proxy address #{options[:proxy]}. Check proxy settings."
20
+ end
21
+ if proxy && proxy.instance_of?(URI::HTTP)
22
+ @agent.set_proxy(proxy.host, proxy.port)
23
+ else
24
+ raise "ProxyError: You have entered an invalid proxy address #{options[:proxy]}. e.g. (http|https)://proxy.com(:port)"
25
+ end
26
+ end
27
+ end
28
+ super
29
+ end
30
+
31
+ def reset_host!
32
+ @last_remote_host = nil
33
+ @last_request_remote = nil
34
+ super
35
+ end
36
+
37
+ def current_url
38
+ last_request_remote? ? remote_response.current_url : super
39
+ end
40
+
41
+ def last_response
42
+ last_request_remote? ? remote_response : super
43
+ end
44
+
45
+ def follow_redirects!
46
+ 5.times do
47
+ follow_redirect! if last_response.redirect?
48
+ end
49
+ raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects." if last_response.redirect?
50
+ end
51
+
52
+ def follow_redirect!
53
+ unless last_response.redirect?
54
+ raise "Last response was not a redirect. Cannot follow_redirect!"
55
+ end
56
+
57
+ get(last_location_header)
58
+ end
59
+
60
+ def process(method, path, *options)
61
+ reset_cache!
62
+ send(method, path, *options)
63
+ follow_redirects!
64
+ end
65
+
66
+ def process_without_redirect(method, path, attributes, headers)
67
+ path = @last_path if path.nil? || path.empty?
68
+
69
+ if remote?(path)
70
+ process_remote_request(method, path, attributes, headers)
71
+ else
72
+ register_local_request
73
+
74
+ path = determine_path(path)
75
+
76
+ reset_cache!
77
+ send("racktest_#{method}", path, attributes, env.merge(headers))
78
+ end
79
+
80
+ @last_path = path
81
+ end
82
+
83
+ # TODO path Capybara to move this into its own method
84
+ def determine_path(path)
85
+ new_uri = URI.parse(path)
86
+ current_uri = URI.parse(current_url)
87
+
88
+ if new_uri.host
89
+ @current_host = new_uri.scheme + '://' + new_uri.host
90
+ end
91
+
92
+ if new_uri.relative?
93
+ path = request_path + path if path.start_with?('?')
94
+
95
+ unless path.start_with?('/')
96
+ folders = request_path.split('/')
97
+ path = (folders[0, folders.size - 1] << path).join('/')
98
+ end
99
+ path = current_host + path
100
+ end
101
+ path
102
+ end
103
+
104
+ alias :racktest_get :get
105
+ def get(path, attributes = {}, headers = {})
106
+ process_without_redirect(:get, path, attributes, headers)
107
+ end
108
+
109
+ alias :racktest_post :post
110
+ def post(path, attributes = {}, headers = {})
111
+ process_without_redirect(:post, path, post_data(attributes), headers)
112
+ end
113
+
114
+ alias :racktest_put :put
115
+ def put(path, attributes = {}, headers = {})
116
+ process_without_redirect(:put, path, attributes, headers)
117
+ end
118
+
119
+ alias :racktest_delete :delete
120
+ def delete(path, attributes = {}, headers = {})
121
+ process_without_redirect(:delete, path, attributes, headers)
122
+ end
123
+
124
+ def post_data(params)
125
+ params.inject({}) do |memo, param|
126
+ case param
127
+ when Hash
128
+ param.each {|attribute, value| memo[attribute] = value }
129
+ memo
130
+ when Array
131
+ case param.last
132
+ when Hash
133
+ param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
134
+ else
135
+ memo[param.first] = param.last
136
+ end
137
+ memo
138
+ end
139
+ end
140
+ end
141
+
142
+ def remote?(url)
143
+ if Capybara.app_host
144
+ true
145
+ else
146
+ host = URI.parse(url).host
147
+
148
+ if host.nil?
149
+ last_request_remote?
150
+ else
151
+ !Capybara::Mechanize.local_hosts.include?(host)
152
+ end
153
+ end
154
+ end
155
+
156
+ attr_reader :agent
157
+
158
+ private
159
+
160
+ def last_location_header
161
+ last_request_remote? ? remote_response.page.response['Location'] : last_response['Location']
162
+ end
163
+
164
+ def last_request_remote?
165
+ !!@last_request_remote
166
+ end
167
+
168
+ def register_local_request
169
+ @last_remote_host = nil
170
+ @last_request_remote = false
171
+ end
172
+
173
+ def process_remote_request(method, url, attributes, headers)
174
+ if remote?(url)
175
+ remote_uri = URI.parse(url)
176
+
177
+ if remote_uri.host.nil?
178
+ remote_host = @last_remote_host || Capybara.app_host || Capybara.default_host
179
+ url = File.join(remote_host, url)
180
+ url = "http://#{url}" unless url =~ /^http:/
181
+ else
182
+ @last_remote_host = "#{remote_uri.host}:#{remote_uri.port}"
183
+ end
184
+
185
+ reset_cache!
186
+ begin
187
+ args = []
188
+ args << attributes unless attributes.empty?
189
+ args << headers unless headers.empty?
190
+ @agent.send(method, url, *args)
191
+ rescue => e
192
+ raise "Received the following error for a #{method.to_s.upcase} request to #{url}: '#{e.message}'"
193
+ end
194
+ @last_request_remote = true
195
+ end
196
+ end
197
+
198
+ def remote_response
199
+ ResponseProxy.new(@agent.current_page) if @agent.current_page
200
+ end
201
+
202
+ class ResponseProxy
203
+ extend Forwardable
204
+
205
+ def_delegator :page, :body
206
+
207
+ attr_reader :page
208
+
209
+ def initialize(page)
210
+ @page = page
211
+ end
212
+
213
+ def current_url
214
+ page.uri.to_s
215
+ end
216
+
217
+ def headers
218
+ # Hax the content-type contains utf8, so Capybara specs are failing, need to ask mailinglist
219
+ headers = page.response
220
+ headers["content-type"].gsub!(';charset=utf-8', '') if headers["content-type"]
221
+ headers
222
+ end
223
+
224
+ def status
225
+ page.code.to_i
226
+ end
227
+
228
+ def redirect?
229
+ [301, 302].include?(status)
230
+ end
231
+
232
+ end
233
+
234
+ end
235
+
@@ -0,0 +1,5 @@
1
+ require 'capybara/mechanize'
2
+
3
+ Before('@mechanize') do
4
+ Capybara.current_driver = :mechanize
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'capybara/mechanize/browser'
2
+
3
+ class Capybara::Mechanize::Driver < Capybara::RackTest::Driver
4
+
5
+ def initialize(app = nil, options = {})
6
+ if !app && !Capybara.app_host
7
+ raise ArgumentError, "You have to set at least Capybara.app_host or Capybara.app"
8
+ end
9
+
10
+ @app, @options = app, options
11
+ end
12
+
13
+ def remote?(url)
14
+ browser.remote?(url)
15
+ end
16
+
17
+ def browser
18
+ @browser ||= Capybara::Mechanize::Browser.new(app, options)
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module Mechanize
3
+ VERSION = '0.3.0.rc0'
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ require 'capybara'
2
+
3
+ module Capybara::Mechanize
4
+ class << self
5
+
6
+ # Host that should be considered local (includes default_host)
7
+ def local_hosts
8
+ @local_hosts ||= begin
9
+ default_host = URI.parse(Capybara.default_host || "").host || Capybara.default_host
10
+ [default_host].compact
11
+ end
12
+ end
13
+
14
+ def local_hosts=(hosts)
15
+ @local_hosts = hosts
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'capybara/mechanize/driver'
21
+
22
+ Capybara.register_driver :mechanize do |app|
23
+ Capybara::Mechanize::Driver.new(app, options = {})
24
+ end
@@ -0,0 +1,41 @@
1
+ require 'capybara/spec/test_app'
2
+
3
+ class ExtendedTestApp < TestApp#< Sinatra::Base
4
+ set :environment, :production # so we don't get debug info that makes our test pass!
5
+
6
+ get %r{/redirect_to/(.*)} do
7
+ redirect params[:captures]
8
+ end
9
+
10
+ get '/form_with_relative_action_to_host' do
11
+ %{<form action="/request_info/host" method="post">
12
+ <input type="submit" value="submit" />
13
+ </form>}
14
+ end
15
+
16
+ get '/request_info/form_with_no_action' do
17
+ %{<form method="post">
18
+ <input type="submit" value="submit" />
19
+ </form>}
20
+ end
21
+
22
+ get '/relative_link_to_host' do
23
+ %{<a href="/request_info/host">host</a>}
24
+ end
25
+
26
+ get '/request_info/*' do
27
+ current_request_info
28
+ end
29
+
30
+ post '/request_info/*' do
31
+ current_request_info
32
+ end
33
+
34
+
35
+ private
36
+
37
+ def current_request_info
38
+ "Current host is #{request.url}, method #{request.request_method.downcase}"
39
+ end
40
+ end
41
+
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Capybara::Driver::Mechanize, in local model" do
4
+ before do
5
+ @driver = Capybara::Mechanize::Driver.new(ExtendedTestApp)
6
+ end
7
+
8
+ it "should throw an error when no rack app is given without an app host" do
9
+ running do
10
+ Capybara::Mechanize::Driver.new
11
+ end.should raise_error(ArgumentError, "You have to set at least Capybara.app_host or Capybara.app")
12
+ end
13
+
14
+ it_should_behave_like "driver"
15
+ it_should_behave_like "driver with header support"
16
+ it_should_behave_like "driver with status code support"
17
+ it_should_behave_like "driver with cookies support"
18
+ it_should_behave_like "driver with infinite redirect detection"
19
+
20
+ it "should default to local mode for relative paths" do
21
+ @driver.should_not be_remote('/')
22
+ end
23
+
24
+ it "should default to local mode for the default host" do
25
+ @driver.should_not be_remote('http://www.example.com')
26
+ end
27
+
28
+ context "with an app_host" do
29
+
30
+ before do
31
+ Capybara.app_host = 'http://www.remote.com'
32
+ end
33
+
34
+ after do
35
+ Capybara.app_host = nil
36
+ end
37
+
38
+ it "should treat urls as remote" do
39
+ @driver.should be_remote('http://www.remote.com')
40
+ end
41
+ end
42
+
43
+ context "with a default url, no app host" do
44
+ before :each do
45
+ Capybara.default_host = 'www.local.com'
46
+ end
47
+
48
+ it "should allow local hosts to be set" do
49
+ Capybara::Mechanize.local_hosts = ['subdomain.local.com']
50
+ @driver.should_not be_remote('http://subdomain.local.com')
51
+ end
52
+
53
+ it "should treat urls with the same host names as local" do
54
+ @driver.should_not be_remote('http://www.local.com')
55
+ end
56
+
57
+ it "should treat other urls as remote" do
58
+ @driver.should be_remote('http://www.remote.com')
59
+ end
60
+
61
+ it "should treat relative paths as remote if the previous request was remote" do
62
+ @driver.visit(REMOTE_TEST_URL)
63
+ @driver.should be_remote('/some_relative_link')
64
+ end
65
+
66
+ it "should treat relative paths as local if the previous request was local" do
67
+ @driver.visit('http://www.local.com')
68
+ @driver.should_not be_remote('/some_relative_link')
69
+ end
70
+
71
+ it "should receive the right host" do
72
+ @driver.visit('http://www.local.com/host')
73
+ should_be_a_local_get
74
+ end
75
+
76
+ it "should consider relative paths to be local when the previous request was local" do
77
+ @driver.visit('http://www.local.com/host')
78
+ @driver.visit('/host')
79
+
80
+ should_be_a_local_get
81
+ @driver.should_not be_remote('/first_local')
82
+ end
83
+
84
+ it "should consider relative paths to be remote when the previous request was remote" do
85
+ @driver.visit("#{REMOTE_TEST_URL}/host")
86
+ @driver.get('/host')
87
+
88
+ should_be_a_remote_get
89
+ @driver.should be_remote('/second_remote')
90
+ end
91
+
92
+ it "should always switch to the right context" do
93
+ @driver.visit('http://www.local.com/host')
94
+ @driver.get('/host')
95
+ @driver.get("#{REMOTE_TEST_URL}/host")
96
+ @driver.get('/host')
97
+ @driver.get('http://www.local.com/host')
98
+
99
+ should_be_a_local_get
100
+ @driver.should_not be_remote('/second_local')
101
+ end
102
+
103
+ it "should follow redirects from local to remote" do
104
+ @driver.visit("http://www.local.com/redirect_to/#{REMOTE_TEST_URL}/host")
105
+ should_be_a_remote_get
106
+ end
107
+
108
+ it "should follow redirects from remote to local" do
109
+ @driver.visit("#{REMOTE_TEST_URL}/redirect_to/http://www.local.com/host")
110
+ should_be_a_local_get
111
+ end
112
+
113
+ after :each do
114
+ Capybara.default_host = nil
115
+ end
116
+
117
+ it "should raise a useful error for sites that return a 404, because it is probably a misconfiguration" do
118
+ lambda {
119
+ @driver.visit("http://iamreallysurethatthisdoesntexist.com/canttouchthis")
120
+ }.should raise_error(%r{Received the following error for a GET request to http://iamreallysurethatthisdoesntexist.com/canttouchthis:})
121
+ end
122
+ end
123
+
124
+ it "should include the right host when remote" do
125
+ @driver.visit("#{REMOTE_TEST_URL}/host")
126
+ should_be_a_remote_get
127
+ end
128
+
129
+ describe '#reset!' do
130
+ before :each do
131
+ Capybara.default_host = 'http://www.local.com'
132
+ end
133
+
134
+ it 'should reset remote host' do
135
+ @driver.visit("#{REMOTE_TEST_URL}/host")
136
+ should_be_a_remote_get
137
+ @driver.reset!
138
+ @driver.visit("/host")
139
+ should_be_a_local_get
140
+ end
141
+ end
142
+
143
+ def should_be_a_remote_get
144
+ @driver.body.should include(REMOTE_TEST_URL)
145
+ end
146
+
147
+ def should_be_a_local_get
148
+ @driver.body.should include("www.local.com")
149
+ end
150
+
151
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Mechanize::Driver do
4
+ before(:each) do
5
+ Capybara.app_host = REMOTE_TEST_URL
6
+ end
7
+
8
+ after(:each) do
9
+ Capybara.app_host = nil
10
+ end
11
+
12
+ before do
13
+ @driver = Capybara::Mechanize::Driver.new
14
+ end
15
+
16
+ context "in remote mode" do
17
+ it "should not throw an error when no rack app is given" do
18
+ running do
19
+ Capybara::Mechanize::Driver.new
20
+ end.should_not raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should pass arguments through to a get request" do
24
+ @driver.visit("#{REMOTE_TEST_URL}/form/get", {:form => "success"})
25
+ @driver.body.should include('success')
26
+ end
27
+
28
+ it "should pass arguments through to a post request" do
29
+ @driver.post("#{REMOTE_TEST_URL}/form", {:form => "success"})
30
+ @driver.body.should include('success')
31
+ end
32
+
33
+ context "for a post request" do
34
+
35
+ it "should transform nested map in post data" do
36
+ @driver.post("#{REMOTE_TEST_URL}/form", {:form => {:key => "value"}})
37
+ @driver.body.should include('key: value')
38
+ end
39
+
40
+ end
41
+
42
+ context "process remote request" do
43
+
44
+ it "should transform nested map in post data" do
45
+ @driver.submit(:post, "#{REMOTE_TEST_URL}/form", {:form => {:key => "value"}})
46
+ @driver.body.should include('key: value')
47
+ end
48
+
49
+ end
50
+
51
+ it_should_behave_like "driver"
52
+ it_should_behave_like "driver with header support"
53
+ it_should_behave_like "driver with status code support"
54
+ it_should_behave_like "driver with cookies support"
55
+ it_should_behave_like "driver with infinite redirect detection"
56
+ end
57
+
58
+ end
59
+
60
+ describe "Capybara::Mechanize::Driver, browser" do
61
+ before(:each) do
62
+ Capybara.app_host = REMOTE_TEST_URL
63
+ end
64
+
65
+ after(:each) do
66
+ Capybara.app_host = nil
67
+ end
68
+ context "in remote mode" do
69
+ it "should not throw an error when empty option is passed" do
70
+ running do
71
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {})
72
+ end.should_not raise_error()
73
+ end
74
+
75
+ it "should throw an error when bad proxy option is passed" do
76
+ running do
77
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => BAD_PROXY}).browser
78
+ end.should raise_error("ProxyError: You have entered an invalid proxy address #{BAD_PROXY}. e.g. (http|https)://proxy.com(:port)")
79
+ end
80
+
81
+ it "should not throw an error when good proxy option is passed" do
82
+ running do
83
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => GOOD_PROXY}).browser
84
+ end.should_not raise_error()
85
+ end
86
+
87
+ it "should not throw an error when good proxy with port option is passed" do
88
+ running do
89
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => PROXY_WITH_PORT}).browser
90
+ end.should_not raise_error()
91
+ end
92
+
93
+
94
+ end
95
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Session do
4
+ context 'with mechanize driver' do
5
+ before do
6
+ @session = Capybara::Session.new(:mechanize, TestApp)
7
+ Capybara.default_host = 'http://www.local.com'
8
+ end
9
+
10
+ describe '#driver' do
11
+ it "should be a mechanize driver" do
12
+ @session.driver.should be_an_instance_of(Capybara::Mechanize::Driver)
13
+ end
14
+ end
15
+
16
+ describe '#mode' do
17
+ it "should remember the mode" do
18
+ @session.mode.should == :mechanize
19
+ end
20
+ end
21
+
22
+ describe '#click_link' do
23
+ it "should use data-method if available" do
24
+ @session.visit "/with_html"
25
+ @session.click_link "A link with data-method"
26
+ @session.body.should include('The requested object was deleted')
27
+ end
28
+ end
29
+
30
+ it "should use the last remote url when following relative links" do
31
+ @session.visit("#{REMOTE_TEST_URL}/relative_link_to_host")
32
+ @session.click_link "host"
33
+ @session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/host, method get")
34
+ end
35
+
36
+ it "should use the last remote url when submitting a form with a relative action" do
37
+ @session.visit("#{REMOTE_TEST_URL}/form_with_relative_action_to_host")
38
+ @session.click_button "submit"
39
+ @session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/host, method post")
40
+ end
41
+
42
+ it "should use the last url when submitting a form with no action" do
43
+ @session.visit("#{REMOTE_TEST_URL}/request_info/form_with_no_action")
44
+ @session.click_button "submit"
45
+ @session.body.should include("Current host is #{REMOTE_TEST_URL}/request_info/form_with_no_action, method post")
46
+ end
47
+
48
+ it_should_behave_like "session"
49
+ it_should_behave_like "session without javascript support"
50
+ it_should_behave_like "session with headers support"
51
+ it_should_behave_like "session with status code support"
52
+ end
53
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Session do
4
+ context 'with remote mechanize driver' do
5
+ before(:each) do
6
+ Capybara.app_host = REMOTE_TEST_URL
7
+ end
8
+
9
+ after(:each) do
10
+ Capybara.app_host = nil
11
+ end
12
+
13
+
14
+ before do
15
+ @session = Capybara::Session.new(:mechanize)
16
+ end
17
+
18
+ describe '#driver' do
19
+ it "should be a mechanize driver" do
20
+ @session.driver.should be_an_instance_of(Capybara::Mechanize::Driver)
21
+ end
22
+ end
23
+
24
+ describe '#mode' do
25
+ it "should remember the mode" do
26
+ @session.mode.should == :mechanize
27
+ end
28
+ end
29
+
30
+ describe '#click_link' do
31
+ it "should use data-method if available" do
32
+ @session.visit "/with_html"
33
+ @session.click_link "A link with data-method"
34
+ @session.body.should include('The requested object was deleted')
35
+ end
36
+ end
37
+
38
+ # Pending: Still 16 failing tests here (result is 706 examples, 16 failures, instead of 385 examples)
39
+ # it_should_behave_like "session"
40
+
41
+ it_should_behave_like "session without javascript support"
42
+ it_should_behave_like "session with headers support"
43
+ it_should_behave_like "session with status code support"
44
+ end
45
+ end
@@ -0,0 +1,37 @@
1
+ require 'bundler/setup'
2
+ require 'capybara'
3
+ require 'capybara/mechanize'
4
+ require 'artifice'
5
+
6
+ require 'sinatra'
7
+
8
+ require 'capybara/spec/extended_test_app'
9
+
10
+ # TODO move this stuff into capybara
11
+ require 'capybara/spec/driver'
12
+ require 'capybara/spec/session'
13
+
14
+ alias :running :lambda
15
+
16
+ Capybara.default_wait_time = 0 # less timeout so tests run faster
17
+
18
+ RSpec.configure do |config|
19
+ config.before(:all) do
20
+ Artifice.activate_with(ExtendedTestApp)
21
+ end
22
+
23
+ config.after do
24
+ Capybara.default_selector = :xpath
25
+ Capybara::Mechanize.local_hosts = nil
26
+ end
27
+
28
+ config.after(:all) do
29
+ Artifice.deactivate
30
+ end
31
+ # config.filter_run :focus => true
32
+ end
33
+
34
+ REMOTE_TEST_URL = "http://localhost"
35
+ GOOD_PROXY = "http://proxy.com"
36
+ BAD_PROXY = "fasfasfasfasf"
37
+ PROXY_WITH_PORT = "http://proxy.com:520"
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbc-capybara-mechanize-with-proxy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15424037
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ - rc
11
+ - 0
12
+ version: 0.3.0.rc0
13
+ platform: ruby
14
+ authors:
15
+ - Jeroen van Dijk
16
+ - Matthew Crouch
17
+ - Voke Ransom Anighoro
18
+ autorequire:
19
+ bindir: bin
20
+ cert_chain: []
21
+
22
+ date: 2011-10-28 00:00:00 Z
23
+ dependencies:
24
+ - !ruby/object:Gem::Dependency
25
+ name: mechanize
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ hash: 23
33
+ segments:
34
+ - 1
35
+ - 0
36
+ - 0
37
+ version: 1.0.0
38
+ type: :runtime
39
+ version_requirements: *id001
40
+ - !ruby/object:Gem::Dependency
41
+ name: capybara
42
+ prerelease: false
43
+ requirement: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ hash: 23
49
+ segments:
50
+ - 1
51
+ - 0
52
+ - 0
53
+ version: 1.0.0
54
+ type: :runtime
55
+ version_requirements: *id002
56
+ description: RackTest driver for Capybara, but with remote request support thanks to mechanize and added proxy configuration features
57
+ email: ransom4real@gmail.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files: []
63
+
64
+ files:
65
+ - lib/capybara/mechanize/browser.rb
66
+ - lib/capybara/mechanize/cucumber.rb
67
+ - lib/capybara/mechanize/driver.rb
68
+ - lib/capybara/mechanize/version.rb
69
+ - lib/capybara/mechanize.rb
70
+ - lib/capybara/spec/extended_test_app.rb
71
+ - spec/driver/mechanize_driver_spec.rb
72
+ - spec/driver/remote_mechanize_driver_spec.rb
73
+ - spec/session/mechanize_spec.rb
74
+ - spec/session/remote_mechanize_spec.rb
75
+ - spec/spec_helper.rb
76
+ - README.mdown
77
+ homepage: https://github.com/ransom4real/capybara-mechanize
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.5
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: RackTest driver for Capybara with remote request support
110
+ test_files: []
111
+