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.
@@ -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