capybara-envjs-fixes 0.0.3 → 0.0.4
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{capybara-envjs-fixes}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Morrison"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-02}
|
13
13
|
s.description = %q{Fixes on top of capybara-envjs}
|
14
14
|
s.email = %q{jmorrison@thoughtbot.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/capybara_envjs_fixes/cucumber_fixes/base64_upload.rb",
|
29
29
|
"lib/capybara_envjs_fixes/cucumber_fixes/capybara_extensions.rb",
|
30
30
|
"lib/capybara_envjs_fixes/cucumber_fixes/javascript.rb",
|
31
|
+
"lib/capybara_envjs_fixes/cucumber_fixes/redirect_fix.rb",
|
31
32
|
"spec/capybara-envjs-fixes_spec.rb",
|
32
33
|
"spec/spec.opts",
|
33
34
|
"spec/spec_helper.rb"
|
@@ -47,6 +47,107 @@ class Capybara::Driver::Envjs::Node
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class Capybara::Driver::Envjs
|
50
|
+
def initialize(app)
|
51
|
+
default_host = @default_host = (Capybara.default_host || "www.example.com")
|
52
|
+
@default_url = "http://"+@default_host
|
53
|
+
@app_host = (ENV["CAPYBARA_APP_HOST"] || Capybara.app_host || @default_url)
|
54
|
+
|
55
|
+
@rack_test = @app_host == @default_url
|
56
|
+
|
57
|
+
if rack_test?
|
58
|
+
require 'rack/test'
|
59
|
+
class << self; self; end.instance_eval do
|
60
|
+
include ::Rack::Test::Methods
|
61
|
+
alias_method :response, :last_response
|
62
|
+
alias_method :request, :last_request
|
63
|
+
define_method :build_rack_mock_session do
|
64
|
+
Rack::MockSession.new(app, default_host)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@app = app
|
70
|
+
|
71
|
+
master_load = browser.master["load"]
|
72
|
+
|
73
|
+
if rack_test?
|
74
|
+
browser.master["load"] = proc do |*args|
|
75
|
+
if args.size == 2 and args[1].to_s != "[object split_global]"
|
76
|
+
file, window = *args
|
77
|
+
body = nil
|
78
|
+
if file.index(app_host) == 0
|
79
|
+
get(file, {}, env)
|
80
|
+
body = response.body
|
81
|
+
else
|
82
|
+
body = Net::HTTP.get(URI.parse(file))
|
83
|
+
end
|
84
|
+
window["evaluate"].call body
|
85
|
+
else
|
86
|
+
master_load.call *args
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
browser["window"]["$envx"]["connection"] =
|
91
|
+
browser.master["connection"] = @connection = proc do |*args|
|
92
|
+
xhr, responseHandler, data = *args
|
93
|
+
url = xhr.url
|
94
|
+
params = data || {}
|
95
|
+
method = xhr["method"].downcase.to_sym
|
96
|
+
|
97
|
+
e = env;
|
98
|
+
xhr.headers.each do |k, v|
|
99
|
+
next if /^content-type$/i =~ k
|
100
|
+
next if /^content-length$/i =~ k
|
101
|
+
next if /^cookie$/i =~ k
|
102
|
+
e['HTTP_' + k.gsub(/-/o, '_').upcase] = v
|
103
|
+
end
|
104
|
+
if method == :post or method == :put
|
105
|
+
e.merge! "CONTENT_TYPE" => xhr.headers["Content-Type"]
|
106
|
+
end
|
107
|
+
if e["CONTENT_TYPE"] =~ %r{^multipart/form-data;}
|
108
|
+
e["CONTENT_LENGTH"] ||= params.length
|
109
|
+
end
|
110
|
+
times = 0
|
111
|
+
begin
|
112
|
+
if url.index(app_host) == 0
|
113
|
+
url.slice! 0..(app_host.length-1)
|
114
|
+
end
|
115
|
+
send method, url, params, e
|
116
|
+
while response.status == 302 || response.status == 301
|
117
|
+
if (times += 1) > 5
|
118
|
+
raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects."
|
119
|
+
end
|
120
|
+
params = {}
|
121
|
+
method = :get
|
122
|
+
url = response.location
|
123
|
+
if url.index(app_host) == 0
|
124
|
+
url.slice! 0..(app_host.length-1)
|
125
|
+
end
|
126
|
+
send method, url, params, e
|
127
|
+
end
|
128
|
+
rescue Exception => e
|
129
|
+
# print "got #{e} #{response.inspect}\n"
|
130
|
+
raise e
|
131
|
+
end
|
132
|
+
@source = response.body
|
133
|
+
response.headers.each do |k,v|
|
134
|
+
xhr.responseHeaders[k] = v
|
135
|
+
end
|
136
|
+
xhr.status = response.status
|
137
|
+
xhr.responseText = response.body
|
138
|
+
xhr.readyState = 4
|
139
|
+
if url.index(app_host) == 0
|
140
|
+
url.slice! 0..(app_host.length-1)
|
141
|
+
end
|
142
|
+
if url.slice(0..0) == "/"
|
143
|
+
url = app_host+url
|
144
|
+
end
|
145
|
+
xhr.__url = url
|
146
|
+
responseHandler.call
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
50
151
|
def env
|
51
152
|
env = {}
|
52
153
|
begin
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class RedirectContentTypeRemover
|
2
|
+
def initialize(app)
|
3
|
+
@app = app
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
remove_content_type_from_redirect(env)
|
8
|
+
@app.call(env)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def remove_content_type_from_redirect(env)
|
14
|
+
if input_blank?(env)
|
15
|
+
env.delete('CONTENT_TYPE')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def input_blank?(env)
|
20
|
+
input = env['rack.input']
|
21
|
+
return true unless input
|
22
|
+
content = input.read
|
23
|
+
input.rewind
|
24
|
+
content.blank?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Capybara.app = RedirectContentTypeRemover.new(Capybara.app)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-envjs-fixes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Morrison
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-02 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/capybara_envjs_fixes/cucumber_fixes/base64_upload.rb
|
72
72
|
- lib/capybara_envjs_fixes/cucumber_fixes/capybara_extensions.rb
|
73
73
|
- lib/capybara_envjs_fixes/cucumber_fixes/javascript.rb
|
74
|
+
- lib/capybara_envjs_fixes/cucumber_fixes/redirect_fix.rb
|
74
75
|
- spec/capybara-envjs-fixes_spec.rb
|
75
76
|
- spec/spec.opts
|
76
77
|
- spec/spec_helper.rb
|