bbc-capybara-mechanize 0.3.0.rc0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,21 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
10
10
  def initialize(app, options)
11
11
  @agent = ::Mechanize.new
12
12
  @agent.redirect_ok = false
13
-
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
14
28
  super
15
29
  end
16
30
 
@@ -163,7 +177,7 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
163
177
  if remote_uri.host.nil?
164
178
  remote_host = @last_remote_host || Capybara.app_host || Capybara.default_host
165
179
  url = File.join(remote_host, url)
166
- url = "http://#{url}" unless url.include?("http")
180
+ url = "http://#{url}" unless url =~ /^http:/ or url =~ /^https:/
167
181
  else
168
182
  @last_remote_host = "#{remote_uri.host}:#{remote_uri.port}"
169
183
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Mechanize
3
- VERSION = '0.3.0.rc0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -56,3 +56,40 @@ describe Capybara::Mechanize::Driver do
56
56
  end
57
57
 
58
58
  end
59
+
60
+ describe "Capybara::Mechanize::Driver, browser" do
61
+
62
+ before(:each) do
63
+ Capybara.app_host = REMOTE_TEST_URL
64
+ end
65
+
66
+ after(:each) do
67
+ Capybara.app_host = nil
68
+ end
69
+
70
+ context "in remote mode" do
71
+ it "should not throw an error when empty option is passed" do
72
+ running do
73
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {})
74
+ end.should_not raise_error()
75
+ end
76
+
77
+ it "should throw an error when bad proxy option is passed" do
78
+ running do
79
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => BAD_PROXY}).browser
80
+ end.should raise_error("ProxyError: You have entered an invalid proxy address #{BAD_PROXY}. e.g. (http|https)://proxy.com(:port)")
81
+ end
82
+
83
+ it "should not throw an error when good proxy option is passed" do
84
+ running do
85
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => GOOD_PROXY}).browser
86
+ end.should_not raise_error()
87
+ end
88
+
89
+ it "should not throw an error when good proxy with port option is passed" do
90
+ running do
91
+ Capybara::Mechanize::Driver.new(ExtendedTestApp, {:proxy => PROXY_WITH_PORT}).browser
92
+ end.should_not raise_error()
93
+ end
94
+ end
95
+ end
data/spec/spec_helper.rb CHANGED
@@ -32,3 +32,6 @@ RSpec.configure do |config|
32
32
  end
33
33
 
34
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 CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbc-capybara-mechanize
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ hash: 17
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 0
9
- - rc0
10
- version: 0.3.0.rc0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeroen van Dijk
@@ -16,39 +16,40 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-31 00:00:00 +01:00
20
- default_executable:
19
+ date: 2012-01-16 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: mechanize
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
27
+ hash: 23
30
28
  segments:
31
29
  - 1
32
30
  - 0
33
31
  - 0
34
32
  version: 1.0.0
33
+ requirement: *id001
35
34
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: capybara
39
35
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
36
+ name: mechanize
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
43
+ hash: 23
45
44
  segments:
46
45
  - 1
47
46
  - 0
48
47
  - 0
49
48
  version: 1.0.0
49
+ requirement: *id002
50
50
  type: :runtime
51
- version_requirements: *id002
51
+ prerelease: false
52
+ name: capybara
52
53
  description: RackTest driver for Capybara, but with remote request support thanks to mechanize
53
54
  email: jeroen@jeevidee.nl
54
55
  executables: []
@@ -70,7 +71,6 @@ files:
70
71
  - spec/session/remote_mechanize_spec.rb
71
72
  - spec/spec_helper.rb
72
73
  - README.mdown
73
- has_rdoc: true
74
74
  homepage: https://github.com/mobzilla/capybara-mechanize
75
75
  licenses: []
76
76
 
@@ -84,6 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
+ hash: 3
87
88
  segments:
88
89
  - 0
89
90
  version: "0"
@@ -92,13 +93,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
94
  - - ">="
94
95
  - !ruby/object:Gem::Version
96
+ hash: 3
95
97
  segments:
96
98
  - 0
97
99
  version: "0"
98
100
  requirements: []
99
101
 
100
102
  rubyforge_project:
101
- rubygems_version: 1.3.7
103
+ rubygems_version: 1.8.10
102
104
  signing_key:
103
105
  specification_version: 3
104
106
  summary: RackTest driver for Capybara with remote request support