rest-client 1.6.7 → 1.6.8.rc1

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.

Potentially problematic release.


This version of rest-client might be problematic. Click here for more details.

@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
3
+ EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
4
+ KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
5
+ MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
6
+ MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
7
+ Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
8
+ Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
9
+ OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
10
+ MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
11
+ NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
12
+ h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMB
13
+ Af8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSY
14
+ JhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQ
15
+ V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp
16
+ myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK
17
+ mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
18
+ vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K
19
+ -----END CERTIFICATE-----
@@ -0,0 +1,8 @@
1
+ The CA path symlinks can be created by c_rehash(1ssl).
2
+
3
+ But in order for the tests to work on Windows, they have to be regular files.
4
+ You can turn them all into regular files by running this on a GNU system:
5
+
6
+ for file in $(find . -type l); do
7
+ cp -iv --remove-destination $(readlink -e $file) $file
8
+ done
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
3
+ EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
4
+ KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
5
+ MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
6
+ MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNv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KmeqvxgydkAQ
15
+ V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp
16
+ myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK
17
+ mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
18
+ vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K
19
+ -----END CERTIFICATE-----
@@ -5,13 +5,23 @@ describe RestClient::Request do
5
5
  it "is successful with the correct ca_file" do
6
6
  request = RestClient::Request.new(
7
7
  :method => :get,
8
- :url => 'https://www.mozilla.com',
8
+ :url => 'https://www.mozilla.org',
9
9
  :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
10
- :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "equifax.crt")
10
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
11
11
  )
12
12
  expect { request.execute }.to_not raise_error
13
13
  end
14
14
 
15
+ # I don' think this feature is useful anymore (under 1.9.3 at the very least).
16
+ #
17
+ # Exceptions in verify_callback are ignored; RestClient has to catch OpenSSL::SSL::SSLError
18
+ # and either re-throw it as is, or throw SSLCertificateNotVerified
19
+ # based on the contents of the message field of the original exception
20
+ #.
21
+ # The client has to handle OpenSSL::SSL::SSLError exceptions anyway,
22
+ # why make them handle both OpenSSL *AND* RestClient exceptions???
23
+ #
24
+ # also see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
15
25
  it "is unsuccessful with an incorrect ca_file" do
16
26
  request = RestClient::Request.new(
17
27
  :method => :get,
@@ -21,5 +31,45 @@ describe RestClient::Request do
21
31
  )
22
32
  expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
23
33
  end
34
+
35
+ it "executes the verify_callback" do
36
+ ran_callback = false
37
+ request = RestClient::Request.new(
38
+ :method => :get,
39
+ :url => 'https://www.mozilla.org',
40
+ :verify_ssl => true,
41
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx|
42
+ ran_callback = true
43
+ preverify_ok
44
+ },
45
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
46
+ )
47
+ expect {request.execute }.to_not raise_error
48
+ ran_callback.should eq(true)
49
+ end
50
+
51
+ it "fails verification when the callback returns false",
52
+ :unless => RestClient::Platform.mac? do
53
+ request = RestClient::Request.new(
54
+ :method => :get,
55
+ :url => 'https://www.mozilla.org',
56
+ :verify_ssl => true,
57
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx| false },
58
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
59
+ )
60
+ expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
61
+ end
62
+
63
+ it "succeeds verification when the callback returns true",
64
+ :unless => RestClient::Platform.mac? do
65
+ request = RestClient::Request.new(
66
+ :method => :get,
67
+ :url => 'https://www.mozilla.org',
68
+ :verify_ssl => true,
69
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt"),
70
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx| true }
71
+ )
72
+ expect { request.execute }.to_not raise_error
73
+ end
24
74
  end
25
75
  end
@@ -1,7 +1,7 @@
1
1
  require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
2
2
 
3
3
  require 'webmock/rspec'
4
- include WebMock
4
+ include WebMock::API
5
5
 
6
6
  describe RestClient do
7
7
 
@@ -9,15 +9,15 @@ describe RestClient do
9
9
  body = 'abc'
10
10
  stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
11
11
  response = RestClient.get "www.example.com"
12
- response.code.should == 200
13
- response.body.should == body
12
+ response.code.should eq 200
13
+ response.body.should eq body
14
14
  end
15
15
 
16
16
  it "a simple request with gzipped content" do
17
17
  stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200, :headers => { 'Content-Encoding' => 'gzip' } )
18
18
  response = RestClient.get "www.example.com"
19
- response.code.should == 200
20
- response.body.should == "i'm gziped\n"
19
+ response.code.should eq 200
20
+ response.body.should eq "i'm gziped\n"
21
21
  end
22
22
 
23
23
  it "a 404" do
@@ -27,10 +27,10 @@ describe RestClient do
27
27
  RestClient.get "www.example.com"
28
28
  raise
29
29
  rescue RestClient::ResourceNotFound => e
30
- e.http_code.should == 404
31
- e.response.code.should == 404
32
- e.response.body.should == body
33
- e.http_body.should == body
30
+ e.http_code.should eq 404
31
+ e.response.code.should eq 404
32
+ e.response.body.should eq body
33
+ e.http_body.should eq body
34
34
  end
35
35
  end
36
36
 
Binary file
data/spec/payload_spec.rb CHANGED
@@ -1,29 +1,30 @@
1
+ # encoding: binary
1
2
  require File.join(File.dirname(File.expand_path(__FILE__)), 'base')
2
3
 
3
4
  describe RestClient::Payload do
4
5
  context "A regular Payload" do
5
6
  it "should use standard enctype as default content-type" do
6
7
  RestClient::Payload::UrlEncoded.new({}).headers['Content-Type'].
7
- should == 'application/x-www-form-urlencoded'
8
+ should eq 'application/x-www-form-urlencoded'
8
9
  end
9
10
 
10
11
  it "should form properly encoded params" do
11
12
  RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
12
- should == "foo=bar"
13
+ should eq "foo=bar"
13
14
  ["foo=bar&baz=qux", "baz=qux&foo=bar"].should include(
14
15
  RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
15
16
  end
16
17
 
17
18
  it "should escape parameters" do
18
19
  RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'}).to_s.
19
- should == "foo%20=bar"
20
+ should eq "foo%20=bar"
20
21
  end
21
22
 
22
23
  it "should properly handle hashes as parameter" do
23
24
  RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'}}).to_s.
24
- should == "foo[bar]=baz"
25
+ should eq "foo[bar]=baz"
25
26
  RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'}}}).to_s.
26
- should == "foo[bar][baz]=qux"
27
+ should eq "foo[bar][baz]=qux"
27
28
  end
28
29
 
29
30
  it "should handle many attributes inside a hash" do
@@ -43,18 +44,18 @@ describe RestClient::Payload do
43
44
 
44
45
  it "should form properly use symbols as parameters" do
45
46
  RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
46
- should == "foo=bar"
47
+ should eq "foo=bar"
47
48
  RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz}}).to_s.
48
- should == "foo[bar]=baz"
49
+ should eq "foo[bar]=baz"
49
50
  end
50
51
 
51
52
  it "should properly handle arrays as repeated parameters" do
52
53
  RestClient::Payload::UrlEncoded.new({:foo => ['bar']}).to_s.
53
- should == "foo[]=bar"
54
+ should eq "foo[]=bar"
54
55
  RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s.
55
- should == "foo[]=bar&foo[]=baz"
56
+ should eq "foo[]=bar&foo[]=baz"
56
57
  end
57
-
58
+
58
59
  it 'should not close if stream already closed' do
59
60
  p = RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'})
60
61
  3.times {p.close}
@@ -65,10 +66,10 @@ describe RestClient::Payload do
65
66
  context "A multipart Payload" do
66
67
  it "should use standard enctype as default content-type" do
67
68
  m = RestClient::Payload::Multipart.new({})
68
- m.stub!(:boundary).and_return(123)
69
- m.headers['Content-Type'].should == 'multipart/form-data; boundary=123'
69
+ m.stub(:boundary).and_return(123)
70
+ m.headers['Content-Type'].should eq 'multipart/form-data; boundary=123'
70
71
  end
71
-
72
+
72
73
  it 'should not error on close if stream already closed' do
73
74
  m = RestClient::Payload::Multipart.new(:file => File.new(File.join(File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg')))
74
75
  3.times {m.close}
@@ -76,7 +77,7 @@ describe RestClient::Payload do
76
77
 
77
78
  it "should form properly separated multipart data" do
78
79
  m = RestClient::Payload::Multipart.new([[:bar, "baz"], [:foo, "bar"]])
79
- m.to_s.should == <<-EOS
80
+ m.to_s.should eq <<-EOS
80
81
  --#{m.boundary}\r
81
82
  Content-Disposition: form-data; name="bar"\r
82
83
  \r
@@ -91,7 +92,7 @@ bar\r
91
92
 
92
93
  it "should not escape parameters names" do
93
94
  m = RestClient::Payload::Multipart.new([["bar ", "baz"]])
94
- m.to_s.should == <<-EOS
95
+ m.to_s.should eq <<-EOS
95
96
  --#{m.boundary}\r
96
97
  Content-Disposition: form-data; name="bar "\r
97
98
  \r
@@ -103,12 +104,12 @@ baz\r
103
104
  it "should form properly separated multipart data" do
104
105
  f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
105
106
  m = RestClient::Payload::Multipart.new({:foo => f})
106
- m.to_s.should == <<-EOS
107
+ m.to_s.should eq <<-EOS
107
108
  --#{m.boundary}\r
108
109
  Content-Disposition: form-data; name="foo"; filename="master_shake.jpg"\r
109
110
  Content-Type: image/jpeg\r
110
111
  \r
111
- #{IO.read(f.path)}\r
112
+ #{File.open(f.path, 'rb'){|bin| bin.read}}\r
112
113
  --#{m.boundary}--\r
113
114
  EOS
114
115
  end
@@ -116,12 +117,12 @@ Content-Type: image/jpeg\r
116
117
  it "should ignore the name attribute when it's not set" do
117
118
  f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
118
119
  m = RestClient::Payload::Multipart.new({nil => f})
119
- m.to_s.should == <<-EOS
120
+ m.to_s.should eq <<-EOS
120
121
  --#{m.boundary}\r
121
122
  Content-Disposition: form-data; filename="master_shake.jpg"\r
122
123
  Content-Type: image/jpeg\r
123
124
  \r
124
- #{IO.read(f.path)}\r
125
+ #{File.open(f.path, 'rb'){|bin| bin.read}}\r
125
126
  --#{m.boundary}--\r
126
127
  EOS
127
128
  end
@@ -131,19 +132,19 @@ Content-Type: image/jpeg\r
131
132
  f.instance_eval "def content_type; 'text/plain'; end"
132
133
  f.instance_eval "def original_filename; 'foo.txt'; end"
133
134
  m = RestClient::Payload::Multipart.new({:foo => f})
134
- m.to_s.should == <<-EOS
135
+ m.to_s.should eq <<-EOS
135
136
  --#{m.boundary}\r
136
137
  Content-Disposition: form-data; name="foo"; filename="foo.txt"\r
137
138
  Content-Type: text/plain\r
138
139
  \r
139
- #{IO.read(f.path)}\r
140
+ #{File.open(f.path, 'rb'){|bin| bin.read}}\r
140
141
  --#{m.boundary}--\r
141
142
  EOS
142
143
  end
143
144
 
144
145
  it "should handle hash in hash parameters" do
145
146
  m = RestClient::Payload::Multipart.new({:bar => {:baz => "foo"}})
146
- m.to_s.should == <<-EOS
147
+ m.to_s.should eq <<-EOS
147
148
  --#{m.boundary}\r
148
149
  Content-Disposition: form-data; name="bar[baz]"\r
149
150
  \r
@@ -155,12 +156,12 @@ foo\r
155
156
  f.instance_eval "def content_type; 'text/plain'; end"
156
157
  f.instance_eval "def original_filename; 'foo.txt'; end"
157
158
  m = RestClient::Payload::Multipart.new({:foo => {:bar => f}})
158
- m.to_s.should == <<-EOS
159
+ m.to_s.should eq <<-EOS
159
160
  --#{m.boundary}\r
160
161
  Content-Disposition: form-data; name="foo[bar]"; filename="foo.txt"\r
161
162
  Content-Type: text/plain\r
162
163
  \r
163
- #{IO.read(f.path)}\r
164
+ #{File.open(f.path, 'rb'){|bin| bin.read}}\r
164
165
  --#{m.boundary}--\r
165
166
  EOS
166
167
  end
@@ -171,23 +172,23 @@ Content-Type: text/plain\r
171
172
  it "should properly determine the size of file payloads" do
172
173
  f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
173
174
  payload = RestClient::Payload.generate(f)
174
- payload.size.should == 22_545
175
- payload.length.should == 22_545
175
+ payload.size.should eq 76_988
176
+ payload.length.should eq 76_988
176
177
  end
177
178
 
178
179
  it "should properly determine the size of other kinds of streaming payloads" do
179
180
  s = StringIO.new 'foo'
180
181
  payload = RestClient::Payload.generate(s)
181
- payload.size.should == 3
182
- payload.length.should == 3
182
+ payload.size.should eq 3
183
+ payload.length.should eq 3
183
184
 
184
185
  begin
185
186
  f = Tempfile.new "rest-client"
186
187
  f.write 'foo bar'
187
188
 
188
189
  payload = RestClient::Payload.generate(f)
189
- payload.size.should == 7
190
- payload.length.should == 7
190
+ payload.size.should eq 7
191
+ payload.length.should eq 7
191
192
  ensure
192
193
  f.close
193
194
  end
@@ -230,5 +231,14 @@ Content-Type: text/plain\r
230
231
  it "should recognize other payloads that can be streamed" do
231
232
  RestClient::Payload.generate(StringIO.new('foo')).should be_kind_of(RestClient::Payload::Streamed)
232
233
  end
234
+
235
+ # hashery gem introduces Hash#read convenience method. Existence of #read method used to determine of content is streameable :/
236
+ it "shouldn't treat hashes as streameable" do
237
+ RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
238
+ end
239
+ end
240
+
241
+ class HashMapForTesting < Hash
242
+ alias :read :[]
233
243
  end
234
244
  end
@@ -2,16 +2,16 @@ require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
2
2
 
3
3
  describe RestClient::RawResponse do
4
4
  before do
5
- @tf = mock("Tempfile", :read => "the answer is 42", :open => true)
6
- @net_http_res = mock('net http response')
5
+ @tf = double("Tempfile", :read => "the answer is 42", :open => true)
6
+ @net_http_res = double('net http response')
7
7
  @response = RestClient::RawResponse.new(@tf, @net_http_res, {})
8
8
  end
9
9
 
10
10
  it "behaves like string" do
11
- @response.to_s.should == 'the answer is 42'
11
+ @response.to_s.should eq 'the answer is 42'
12
12
  end
13
13
 
14
14
  it "exposes a Tempfile" do
15
- @response.file.should == @tf
15
+ @response.file.should eq @tf
16
16
  end
17
17
  end
@@ -1,16 +1,16 @@
1
1
  require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
2
2
 
3
3
  require 'webmock/rspec'
4
- include WebMock
4
+ include WebMock::API
5
5
 
6
6
  describe RestClient::Request do
7
7
 
8
8
  it "manage params for get requests" do
9
9
  stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
10
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should == 'foo'
10
+ RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should eq 'foo'
11
11
 
12
12
  stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar', 'params' => 'a'}).to_return(:body => 'foo', :status => 200)
13
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should == 'foo'
13
+ RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should eq 'foo'
14
14
  end
15
15
 
16
16
  it "can use a block to process response" do
@@ -20,21 +20,16 @@ describe RestClient::Request do
20
20
  end
21
21
  stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
22
22
  RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
23
- response_value.should == "foo"
23
+ response_value.should eq "foo"
24
24
  end
25
25
 
26
26
  it 'closes payload if not nil' do
27
27
  test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
28
- initial_count = tmp_count
29
28
 
30
29
  stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
31
30
  RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
32
31
 
33
- tmp_count.should == initial_count
32
+ test_file.closed?.should be_true
34
33
  end
35
34
 
36
35
  end
37
-
38
- def tmp_count
39
- Dir.glob(Dir::tmpdir + "/*").size
40
- end