dbalatero-typhoeus 0.0.20
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/ext/typhoeus/Makefile +157 -0
- data/ext/typhoeus/extconf.rb +57 -0
- data/ext/typhoeus/native.c +11 -0
- data/ext/typhoeus/native.h +11 -0
- data/ext/typhoeus/typhoeus_easy.c +206 -0
- data/ext/typhoeus/typhoeus_easy.h +19 -0
- data/ext/typhoeus/typhoeus_multi.c +213 -0
- data/ext/typhoeus/typhoeus_multi.h +16 -0
- data/lib/typhoeus/easy.rb +210 -0
- data/lib/typhoeus/filter.rb +28 -0
- data/lib/typhoeus/multi.rb +34 -0
- data/lib/typhoeus/remote.rb +306 -0
- data/lib/typhoeus/remote_method.rb +108 -0
- data/lib/typhoeus/remote_proxy_object.rb +48 -0
- data/lib/typhoeus/response.rb +17 -0
- data/lib/typhoeus.rb +53 -0
- data/spec/servers/delay_fixture_server.rb +66 -0
- data/spec/servers/method_server.rb +51 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/typhoeus/easy_spec.rb +148 -0
- data/spec/typhoeus/filter_spec.rb +35 -0
- data/spec/typhoeus/multi_spec.rb +82 -0
- data/spec/typhoeus/remote_method_spec.rb +141 -0
- data/spec/typhoeus/remote_proxy_object_spec.rb +73 -0
- data/spec/typhoeus/remote_spec.rb +699 -0
- data/spec/typhoeus/response_spec.rb +31 -0
- metadata +81 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::RemoteProxyObject do
|
4
|
+
before(:each) do
|
5
|
+
@easy = Typhoeus::Easy.new
|
6
|
+
@easy.method = :get
|
7
|
+
@easy.url = "http://localhost:3001"
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
@pid = start_method_server(3001)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
stop_method_server(@pid)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should take a caller and call the clear_memoized_proxy_objects" do
|
19
|
+
clear_proxy = lambda {}
|
20
|
+
clear_proxy.should_receive(:call)
|
21
|
+
response = Typhoeus::RemoteProxyObject.new(clear_proxy, @easy)
|
22
|
+
response.code.should == 200
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should take an easy object and return the body when requested" do
|
26
|
+
response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
|
27
|
+
@easy.response_code.should == 0
|
28
|
+
response.code.should == 200
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should perform requests only on the first access" do
|
32
|
+
response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
|
33
|
+
response.code.should == 200
|
34
|
+
Typhoeus.should_receive(:perform_easy_requests).exactly(0).times
|
35
|
+
response.code.should == 200
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set the requested_url and requested_http_method on the response" do
|
39
|
+
response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
|
40
|
+
response.requested_url.should == "http://localhost:3001"
|
41
|
+
response.requested_http_method.should == :get
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should call the on_success method with an easy object and proxy to the result of on_success" do
|
45
|
+
klass = Class.new do
|
46
|
+
def initialize(r)
|
47
|
+
@response = r
|
48
|
+
end
|
49
|
+
|
50
|
+
def blah
|
51
|
+
@response.code
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
k = Typhoeus::RemoteProxyObject.new(lambda {}, @easy, :on_success => lambda {|e| klass.new(e)})
|
56
|
+
k.blah.should == 200
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should call the on_failure method with an easy object and proxy to the result of on_failure" do
|
60
|
+
klass = Class.new do
|
61
|
+
def initialize(r)
|
62
|
+
@response = r
|
63
|
+
end
|
64
|
+
|
65
|
+
def blah
|
66
|
+
@response.code
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@easy.url = "http://localhost:3002" #bad port
|
70
|
+
k = Typhoeus::RemoteProxyObject.new(lambda {}, @easy, :on_failure => lambda {|e| klass.new(e)})
|
71
|
+
k.blah.should == 0
|
72
|
+
end
|
73
|
+
end
|