webmachine 1.6.0 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -5
- data/documentation/adapters.md +2 -11
- data/examples/debugger.rb +5 -3
- data/examples/logging.rb +2 -2
- data/examples/webrick.rb +2 -2
- data/lib/webmachine/adapter.rb +0 -3
- data/lib/webmachine/adapters/lazy_request_body.rb +1 -1
- data/lib/webmachine/adapters/rack.rb +38 -34
- data/lib/webmachine/adapters/rack_mapped.rb +1 -2
- data/lib/webmachine/adapters/webrick.rb +11 -12
- data/lib/webmachine/adapters.rb +0 -2
- data/lib/webmachine/application.rb +2 -2
- data/lib/webmachine/chunked_body.rb +1 -1
- data/lib/webmachine/configuration.rb +1 -1
- data/lib/webmachine/constants.rb +12 -12
- data/lib/webmachine/cookie.rb +20 -18
- data/lib/webmachine/decision/conneg.rb +24 -24
- data/lib/webmachine/decision/falsey.rb +0 -1
- data/lib/webmachine/decision/flow.rb +19 -20
- data/lib/webmachine/decision/fsm.rb +4 -4
- data/lib/webmachine/decision/helpers.rb +21 -21
- data/lib/webmachine/dispatcher/route.rb +28 -28
- data/lib/webmachine/dispatcher.rb +3 -2
- data/lib/webmachine/errors.rb +7 -8
- data/lib/webmachine/etags.rb +2 -1
- data/lib/webmachine/header_negotiation.rb +5 -6
- data/lib/webmachine/headers.rb +5 -5
- data/lib/webmachine/media_type.rb +5 -5
- data/lib/webmachine/quoted_string.rb +3 -3
- data/lib/webmachine/request.rb +7 -10
- data/lib/webmachine/rescueable_exception.rb +3 -3
- data/lib/webmachine/resource/authentication.rb +3 -4
- data/lib/webmachine/resource/callbacks.rb +3 -3
- data/lib/webmachine/resource/encodings.rb +3 -9
- data/lib/webmachine/resource.rb +1 -1
- data/lib/webmachine/response.rb +7 -9
- data/lib/webmachine/spec/adapter_lint.rb +67 -69
- data/lib/webmachine/spec/test_resource.rb +22 -22
- data/lib/webmachine/streaming/encoder.rb +3 -2
- data/lib/webmachine/streaming/io_encoder.rb +4 -3
- data/lib/webmachine/trace/fsm.rb +25 -18
- data/lib/webmachine/trace/resource_proxy.rb +10 -9
- data/lib/webmachine/trace/static/http-headers-status-v3.png +0 -0
- data/lib/webmachine/trace/trace_resource.rb +22 -24
- data/lib/webmachine/trace.rb +7 -6
- data/lib/webmachine/translation.rb +3 -3
- data/lib/webmachine/version.rb +1 -1
- metadata +52 -86
- data/.gitignore +0 -31
- data/Gemfile +0 -46
- data/Guardfile +0 -11
- data/RELEASING.md +0 -21
- data/Rakefile +0 -44
- data/lib/webmachine/adapters/httpkit.rb +0 -74
- data/lib/webmachine/adapters/reel.rb +0 -113
- data/memory_test.rb +0 -37
- data/spec/spec_helper.rb +0 -56
- data/spec/webmachine/adapter_spec.rb +0 -39
- data/spec/webmachine/adapters/httpkit_spec.rb +0 -10
- data/spec/webmachine/adapters/rack_mapped_spec.rb +0 -71
- data/spec/webmachine/adapters/rack_spec.rb +0 -62
- data/spec/webmachine/adapters/reel_spec.rb +0 -76
- data/spec/webmachine/adapters/webrick_spec.rb +0 -12
- data/spec/webmachine/application_spec.rb +0 -74
- data/spec/webmachine/chunked_body_spec.rb +0 -30
- data/spec/webmachine/configuration_spec.rb +0 -27
- data/spec/webmachine/cookie_spec.rb +0 -99
- data/spec/webmachine/decision/conneg_spec.rb +0 -166
- data/spec/webmachine/decision/falsey_spec.rb +0 -8
- data/spec/webmachine/decision/flow_spec.rb +0 -1148
- data/spec/webmachine/decision/fsm_spec.rb +0 -163
- data/spec/webmachine/decision/helpers_spec.rb +0 -216
- data/spec/webmachine/dispatcher/rfc3986_percent_decode_spec.rb +0 -22
- data/spec/webmachine/dispatcher/route_spec.rb +0 -248
- data/spec/webmachine/dispatcher_spec.rb +0 -104
- data/spec/webmachine/errors_spec.rb +0 -13
- data/spec/webmachine/etags_spec.rb +0 -75
- data/spec/webmachine/events_spec.rb +0 -58
- data/spec/webmachine/headers_spec.rb +0 -99
- data/spec/webmachine/media_type_spec.rb +0 -85
- data/spec/webmachine/request_spec.rb +0 -273
- data/spec/webmachine/rescueable_exception_spec.rb +0 -15
- data/spec/webmachine/resource/authentication_spec.rb +0 -68
- data/spec/webmachine/response_spec.rb +0 -51
- data/spec/webmachine/trace/fsm_spec.rb +0 -37
- data/spec/webmachine/trace/resource_proxy_spec.rb +0 -34
- data/spec/webmachine/trace/trace_store_spec.rb +0 -29
- data/spec/webmachine/trace_spec.rb +0 -17
- data/webmachine.gemspec +0 -25
@@ -1,273 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Request do
|
4
|
-
subject { request }
|
5
|
-
|
6
|
-
let(:uri) { URI.parse("http://localhost:8080/some/resource") }
|
7
|
-
let(:http_method) { "GET" }
|
8
|
-
let(:headers) { Webmachine::Headers.new }
|
9
|
-
let(:body) { "" }
|
10
|
-
let(:routing_tokens) { nil }
|
11
|
-
let(:base_uri) { nil }
|
12
|
-
let(:request) { Webmachine::Request.new(http_method, uri, headers, body, routing_tokens, base_uri) }
|
13
|
-
|
14
|
-
it "should provide access to the headers via brackets" do
|
15
|
-
subject.headers['Accept'] = "*/*"
|
16
|
-
expect(subject["accept"]).to eq("*/*")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should provide access to the cookies" do
|
20
|
-
subject.headers['Cookie'] = 'name=value;name2=value2';
|
21
|
-
expect(subject.cookies).to eq({ 'name' => 'value', 'name2' => 'value2' })
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should handle cookies with extra whitespace" do
|
25
|
-
subject.headers['Cookie'] = 'name = value; name2 = value2';
|
26
|
-
expect(subject.cookies).to eq({ 'name' => 'value', 'name2' => 'value2' })
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should provide access to the headers via underscored methods" do
|
30
|
-
subject.headers["Accept-Encoding"] = "identity"
|
31
|
-
expect(subject.accept_encoding).to eq("identity")
|
32
|
-
expect(subject.content_md5).to be_nil
|
33
|
-
end
|
34
|
-
|
35
|
-
context "base_uri" do
|
36
|
-
it "should calculate a base URI" do
|
37
|
-
expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/"))
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when base_uri has been explicitly set" do
|
41
|
-
let(:base_uri) { URI.parse("http://localhost:8080/some_base_uri/here") }
|
42
|
-
it "should use the provided base_uri" do
|
43
|
-
expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/some_base_uri/here"))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should provide a hash of query parameters" do
|
49
|
-
subject.uri.query = "foo=bar&baz=bam"
|
50
|
-
expect(subject.query).to eq({"foo" => "bar", "baz" => "bam"})
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should handle = being encoded as a query value." do
|
54
|
-
subject.uri.query = "foo=bar%3D%3D"
|
55
|
-
expect(subject.query).to eq({ "foo" => "bar=="})
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should treat '+' characters in query parameters as spaces" do
|
59
|
-
subject.uri.query = "a%20b=foo+bar&c+d=baz%20quux"
|
60
|
-
expect(subject.query).to eq({"a b" => "foo bar", "c d" => "baz quux"})
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should handle a query parameter value of nil" do
|
64
|
-
subject.uri.query = nil
|
65
|
-
expect(subject.query).to eq({})
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#has_body?' do
|
69
|
-
let(:wreq) do
|
70
|
-
Class.new {
|
71
|
-
def initialize(body); @body = body; end
|
72
|
-
def body; block_given? ? yield(@body) : @body; end
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
subject { request.has_body? }
|
77
|
-
|
78
|
-
context "when body is nil" do
|
79
|
-
let(:body) { nil }
|
80
|
-
|
81
|
-
it { is_expected.to be(false) }
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when body is an empty string" do
|
85
|
-
let(:body) { '' }
|
86
|
-
|
87
|
-
it { is_expected.to be(false) }
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when body is not empty" do
|
91
|
-
let(:body) { 'foo' }
|
92
|
-
|
93
|
-
it { is_expected.to be(true) }
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when body is an empty LazyRequestBody" do
|
97
|
-
let(:body) { Webmachine::Adapters::LazyRequestBody.new(wreq.new('')) }
|
98
|
-
|
99
|
-
it { is_expected.to be(false) }
|
100
|
-
end
|
101
|
-
|
102
|
-
context "when body is a LazyRequestBody" do
|
103
|
-
let(:body) { Webmachine::Adapters::LazyRequestBody.new(wreq.new('foo')) }
|
104
|
-
|
105
|
-
it { is_expected.to be(true) }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#https?' do
|
110
|
-
subject { request.https? }
|
111
|
-
|
112
|
-
context "when the request was issued via HTTPS" do
|
113
|
-
let(:uri) { URI.parse("https://localhost.com:8080/some/resource") }
|
114
|
-
|
115
|
-
it { is_expected.to be(true) }
|
116
|
-
end
|
117
|
-
|
118
|
-
context "when the request was not issued via HTTPS" do
|
119
|
-
let(:uri) { URI.parse("http://localhost.com:8080/some/resource") }
|
120
|
-
|
121
|
-
it { is_expected.to be(false) }
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '#get?' do
|
126
|
-
subject { request.get? }
|
127
|
-
|
128
|
-
context "when the request method is GET" do
|
129
|
-
let(:http_method) { "GET" }
|
130
|
-
|
131
|
-
it { is_expected.to be(true) }
|
132
|
-
end
|
133
|
-
|
134
|
-
context "when the request method is not GET" do
|
135
|
-
let(:http_method) { "POST" }
|
136
|
-
|
137
|
-
it { is_expected.to be(false) }
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe '#head?' do
|
142
|
-
subject { request.head? }
|
143
|
-
|
144
|
-
context "when the request method is HEAD" do
|
145
|
-
let(:http_method) { "HEAD" }
|
146
|
-
|
147
|
-
it { is_expected.to be(true) }
|
148
|
-
end
|
149
|
-
|
150
|
-
context "when the request method is not HEAD" do
|
151
|
-
let(:http_method) { "GET" }
|
152
|
-
|
153
|
-
it { is_expected.to be(false) }
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe '#post?' do
|
158
|
-
subject { request.post? }
|
159
|
-
|
160
|
-
context "when the request method is POST" do
|
161
|
-
let(:http_method) { "POST" }
|
162
|
-
|
163
|
-
it { is_expected.to be(true) }
|
164
|
-
end
|
165
|
-
|
166
|
-
context "when the request method is not POST" do
|
167
|
-
let(:http_method) { "GET" }
|
168
|
-
|
169
|
-
it { is_expected.to be(false) }
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe '#put?' do
|
174
|
-
subject { request.put? }
|
175
|
-
|
176
|
-
context "when the request method is PUT" do
|
177
|
-
let(:http_method) { "PUT" }
|
178
|
-
|
179
|
-
it { is_expected.to be(true) }
|
180
|
-
end
|
181
|
-
|
182
|
-
context "when the request method is not PUT" do
|
183
|
-
let(:http_method) { "GET" }
|
184
|
-
|
185
|
-
it { is_expected.to be(false) }
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe '#delete?' do
|
190
|
-
subject { request.delete? }
|
191
|
-
|
192
|
-
context "when the request method is DELETE" do
|
193
|
-
let(:http_method) { "DELETE" }
|
194
|
-
|
195
|
-
it { is_expected.to be(true) }
|
196
|
-
end
|
197
|
-
|
198
|
-
context "when the request method is not DELETE" do
|
199
|
-
let(:http_method) { "GET" }
|
200
|
-
|
201
|
-
it { is_expected.to be(false) }
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe '#trace?' do
|
206
|
-
subject { request.trace? }
|
207
|
-
|
208
|
-
context "when the request method is TRACE" do
|
209
|
-
let(:http_method) { "TRACE" }
|
210
|
-
|
211
|
-
it { is_expected.to be(true) }
|
212
|
-
end
|
213
|
-
|
214
|
-
context "when the request method is not TRACE" do
|
215
|
-
let(:http_method) { "GET" }
|
216
|
-
|
217
|
-
it { is_expected.to be(false) }
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe '#connect?' do
|
222
|
-
subject { request.connect? }
|
223
|
-
|
224
|
-
context "when the request method is CONNECT" do
|
225
|
-
let(:http_method) { "CONNECT" }
|
226
|
-
|
227
|
-
it { is_expected.to be(true) }
|
228
|
-
end
|
229
|
-
|
230
|
-
context "when the request method is not CONNECT" do
|
231
|
-
let(:http_method) { "GET" }
|
232
|
-
|
233
|
-
it { is_expected.to be(false) }
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe '#options?' do
|
238
|
-
subject { request.options? }
|
239
|
-
|
240
|
-
context "when the request method is OPTIONS" do
|
241
|
-
let(:http_method) { "OPTIONS" }
|
242
|
-
|
243
|
-
it { is_expected.to be(true) }
|
244
|
-
end
|
245
|
-
|
246
|
-
context "when the request method is not OPTIONS" do
|
247
|
-
let(:http_method) { "GET" }
|
248
|
-
|
249
|
-
it { is_expected.to be(false) }
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
describe '#routing_tokens' do
|
254
|
-
subject { request.routing_tokens }
|
255
|
-
|
256
|
-
context "haven't been explicitly set" do
|
257
|
-
let(:routing_tokens) { nil }
|
258
|
-
it "extracts the routing tokens from the path portion of the uri" do
|
259
|
-
expect(subject).to eq(["some", "resource"])
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "have been explicitly set" do
|
264
|
-
let(:routing_tokens) { ["foo", "bar"] }
|
265
|
-
|
266
|
-
it "uses the specified routing_tokens" do
|
267
|
-
expect(subject).to eq(["foo", "bar"])
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
RSpec.describe Webmachine::RescuableException do
|
3
|
-
before { described_class.default! }
|
4
|
-
|
5
|
-
describe ".UNRESCUABLEs" do
|
6
|
-
specify "returns an array of UNRESCUABLE exceptions" do
|
7
|
-
expect(described_class.UNRESCUABLEs).to eq(described_class::UNRESCUABLE_DEFAULTS)
|
8
|
-
end
|
9
|
-
|
10
|
-
specify "returns an array of UNRESCUABLE exceptions, with custom exceptions added" do
|
11
|
-
described_class.remove(Exception)
|
12
|
-
expect(described_class.UNRESCUABLEs).to eq(described_class::UNRESCUABLE_DEFAULTS.dup.concat([Exception]))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Resource::Authentication do
|
4
|
-
subject { Webmachine::Decision::FSM.new(resource, request, response) }
|
5
|
-
let(:method) { 'GET' }
|
6
|
-
let(:uri) { URI.parse("http://localhost/") }
|
7
|
-
let(:headers) { Webmachine::Headers.new }
|
8
|
-
let(:body) { "" }
|
9
|
-
let(:request) { Webmachine::Request.new(method, uri, headers, body) }
|
10
|
-
let(:response) { Webmachine::Response.new }
|
11
|
-
|
12
|
-
def resource_with(&block)
|
13
|
-
klass = Class.new(Webmachine::Resource) do
|
14
|
-
def to_html; "test resource"; end
|
15
|
-
end
|
16
|
-
klass.module_eval(&block) if block_given?
|
17
|
-
klass.new(request, response)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "Basic authentication" do
|
21
|
-
let(:resource) do
|
22
|
-
resource_with do
|
23
|
-
include Webmachine::Resource::Authentication
|
24
|
-
attr_accessor :realm
|
25
|
-
def is_authorized?(auth)
|
26
|
-
basic_auth(auth, @realm || "Webmachine") {|u,p| u == "webmachine" && p == "http" }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when no authorization is sent by the client" do
|
32
|
-
it "should reply with a 401 Unauthorized and a WWW-Authenticate header using Basic" do
|
33
|
-
subject.run
|
34
|
-
expect(response.code).to eq(401)
|
35
|
-
expect(response.headers['WWW-Authenticate']).to eq('Basic realm="Webmachine"')
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should use the specified realm in the WWW-Authenticate header" do
|
39
|
-
resource.realm = "My App"
|
40
|
-
subject.run
|
41
|
-
expect(response.headers['WWW-Authenticate']).to eq('Basic realm="My App"')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when the client sends invalid authorization" do
|
46
|
-
before do
|
47
|
-
headers['Authorization'] = "Basic " + ["invalid:auth"].pack('m*').chomp
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should reply with a 401 Unauthorized and a WWW-Authenticate header using Basic" do
|
51
|
-
subject.run
|
52
|
-
expect(response.code).to eq(401)
|
53
|
-
expect(response.headers['WWW-Authenticate']).to eq('Basic realm="Webmachine"')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when the client sends valid authorization" do
|
58
|
-
before do
|
59
|
-
headers['Authorization'] = "Basic " + ["webmachine:http"].pack('m*').chomp
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not reply with 401 Unauthorized" do
|
63
|
-
subject.run
|
64
|
-
expect(response.code).not_to eq(401)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Response do
|
4
|
-
|
5
|
-
it "should have sane default values" do
|
6
|
-
expect(subject.code).to eq(200)
|
7
|
-
expect(subject.is_redirect?).to be(false)
|
8
|
-
expect(subject.headers).to be_empty
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "a redirected response" do
|
12
|
-
let(:redirect_url) { "/" }
|
13
|
-
|
14
|
-
before(:each) { subject.redirect_to redirect_url }
|
15
|
-
|
16
|
-
its(:is_redirect?) { should be(true) }
|
17
|
-
|
18
|
-
it "should have a proper Location header" do
|
19
|
-
expect(subject.headers["Location"]).to eq(redirect_url)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "setting a cookie" do
|
24
|
-
let(:cookie) { "monster" }
|
25
|
-
let(:cookie_value) { "mash" }
|
26
|
-
|
27
|
-
before(:each) { subject.set_cookie(cookie, cookie_value) }
|
28
|
-
|
29
|
-
it "should have a proper Set-Cookie header" do
|
30
|
-
expect(subject.headers["Set-Cookie"]).to include "monster=mash"
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "setting multiple cookies" do
|
34
|
-
let(:cookie2) { "rodeo" }
|
35
|
-
let(:cookie2_value) { "clown" }
|
36
|
-
let(:cookie3) {"color"}
|
37
|
-
let(:cookie3_value) {"blue"}
|
38
|
-
before(:each) do
|
39
|
-
subject.set_cookie(cookie2, cookie2_value)
|
40
|
-
subject.set_cookie(cookie3, cookie3_value)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should have a proper Set-Cookie header" do
|
44
|
-
expect(subject.headers["Set-Cookie"]).to be_a Array
|
45
|
-
expect(subject.headers["Set-Cookie"]).to include "rodeo=clown"
|
46
|
-
expect(subject.headers["Set-Cookie"]).to include "monster=mash"
|
47
|
-
expect(subject.headers["Set-Cookie"]).to include "color=blue"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Trace::FSM do
|
4
|
-
include_context "default resource"
|
5
|
-
|
6
|
-
subject { Webmachine::Decision::FSM.new(resource, request, response) }
|
7
|
-
before { Webmachine::Trace.trace_store = :memory }
|
8
|
-
|
9
|
-
context "when tracing is enabled" do
|
10
|
-
before { allow(Webmachine::Trace).to receive(:trace?).and_return(true) }
|
11
|
-
|
12
|
-
it "proxies the resource" do
|
13
|
-
expect(subject.resource).to be_kind_of(Webmachine::Trace::ResourceProxy)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "records a trace" do
|
17
|
-
subject.run
|
18
|
-
expect(response.trace).to_not be_empty
|
19
|
-
expect(Webmachine::Trace.traces.size).to eq(1)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "commits the trace to separate storage when the request has finished processing" do
|
23
|
-
expect(Webmachine::Trace).to receive(:record).with(subject.resource.object_id.to_s, response.trace).and_return(true)
|
24
|
-
subject.run
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when tracing is disabled" do
|
29
|
-
before { allow(Webmachine::Trace).to receive(:trace?).and_return(false) }
|
30
|
-
|
31
|
-
it "leaves no trace" do
|
32
|
-
subject.run
|
33
|
-
expect(response.trace).to be_empty
|
34
|
-
expect(Webmachine::Trace.traces).to be_empty
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'webmachine/trace/resource_proxy'
|
3
|
-
|
4
|
-
describe Webmachine::Trace::ResourceProxy do
|
5
|
-
include_context "default resource"
|
6
|
-
subject { described_class.new(resource) }
|
7
|
-
|
8
|
-
it "duck-types all callback methods" do
|
9
|
-
Webmachine::Resource::Callbacks.instance_methods(false).each do |m|
|
10
|
-
expect(subject).to respond_to(m)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it "logs invocations of callbacks" do
|
15
|
-
subject.generate_etag
|
16
|
-
expect(response.trace).to eq([{:type => :attempt, :name => "(default)#generate_etag"},
|
17
|
-
{:type => :result, :value => nil}])
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
it "logs invocations of body-producing methods" do
|
22
|
-
expect(subject.content_types_provided).to eq([["text/html", :to_html]])
|
23
|
-
subject.to_html
|
24
|
-
expect(response.trace[-2][:type]).to eq(:attempt)
|
25
|
-
expect(response.trace[-2][:name]).to match(/to_html$/)
|
26
|
-
expect(response.trace[-2][:source]).to include("spec_helper.rb") if response.trace[-2][:source]
|
27
|
-
expect(response.trace[-1]).to eq({:type => :result, :value => "<html><body>Hello, world!</body></html>"})
|
28
|
-
end
|
29
|
-
|
30
|
-
it "sets the trace id header when the request has finished processing" do
|
31
|
-
subject.finish_request
|
32
|
-
expect(response.headers["X-Webmachine-Trace-Id"]).to eq(subject.object_id.to_s)
|
33
|
-
end
|
34
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
shared_examples_for "trace storage" do
|
5
|
-
it { is_expected.to respond_to(:[]=) }
|
6
|
-
it { is_expected.to respond_to(:keys) }
|
7
|
-
it { is_expected.to respond_to(:fetch) }
|
8
|
-
|
9
|
-
it "stores a trace" do
|
10
|
-
subject["foo"] = [:bar]
|
11
|
-
expect(subject.fetch("foo")).to eq([:bar])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "lists a stored trace in the keys" do
|
15
|
-
subject["foo"] = [:bar]
|
16
|
-
expect(subject.keys).to eq(["foo"])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe Webmachine::Trace::PStoreTraceStore do
|
21
|
-
subject { described_class.new("./wmtrace") }
|
22
|
-
after { FileUtils.rm_rf("./wmtrace") }
|
23
|
-
it_behaves_like "trace storage"
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "Webmachine::Trace :memory Trace Store (Hash)" do
|
27
|
-
subject { Hash.new }
|
28
|
-
it_behaves_like "trace storage"
|
29
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Webmachine::Trace do
|
4
|
-
subject { described_class }
|
5
|
-
|
6
|
-
context "determining whether the resource should be traced" do
|
7
|
-
include_context "default resource"
|
8
|
-
it "does not trace by default" do
|
9
|
-
expect(subject.trace?(resource)).to be(false)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "traces when the resource enables tracing" do
|
13
|
-
expect(resource).to receive(:trace?).and_return(true)
|
14
|
-
expect(subject.trace?(resource)).to be(true)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/webmachine.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
$:.push File.expand_path("../lib", __FILE__)
|
2
|
-
require 'webmachine/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = "webmachine"
|
6
|
-
gem.version = Webmachine::VERSION
|
7
|
-
gem.summary = %Q{webmachine is a toolkit for building HTTP applications,}
|
8
|
-
gem.description = <<-DESC.gsub(/\s+/, ' ')
|
9
|
-
webmachine is a toolkit for building HTTP applications in a declarative fashion, that avoids
|
10
|
-
the confusion of going through a CGI-style interface like Rack. It is strongly influenced
|
11
|
-
by the original Erlang project of the same name and shares its opinionated nature about HTTP.
|
12
|
-
DESC
|
13
|
-
gem.homepage = "http://github.com/seancribbs/webmachine-ruby"
|
14
|
-
gem.authors = ["Sean Cribbs"]
|
15
|
-
gem.email = ["sean@basho.com"]
|
16
|
-
gem.license = "Apache-2.0"
|
17
|
-
|
18
|
-
gem.add_runtime_dependency(%q<i18n>, [">= 0.4.0"])
|
19
|
-
gem.add_runtime_dependency(%q<multi_json>)
|
20
|
-
gem.add_runtime_dependency(%q<as-notifications>, ["~> 1.0"])
|
21
|
-
|
22
|
-
ignores = File.read(".gitignore").split(/\r?\n/).reject{ |f| f =~ /^(#.+|\s*)$/ }.map {|f| Dir[f] }.flatten
|
23
|
-
gem.files = (Dir['**/*','.gitignore'] - ignores).reject {|f| !File.file?(f) }
|
24
|
-
gem.test_files = (Dir['spec/**/*','features/**/*','.gitignore'] - ignores).reject {|f| !File.file?(f) }
|
25
|
-
end
|