spec/integration/riak/http_backends_spec.rb in riak-client-1.2.0 vs spec/integration/riak/http_backends_spec.rb in riak-client-1.4.0
- old
+ new
@@ -104,31 +104,41 @@
end
end
end
end
- class Reader < Array
+ class SizelessReader < Array
def read(*args)
shift
end
- def size
- join.size
- end
- end
-
- class SizelessReader < Reader
undef :size
end
describe 'NetHTTPBackend' do
subject { Riak::Client::NetHTTPBackend.new(@client, @client.node) }
- let(:file) { File.open(__FILE__) }
- let(:sized) { Reader.new(["foo", "bar", "baz"]) }
- let(:sizeless) { SizelessReader.new(["foo", "bar", "baz"]) }
- it "should set the content-length or transfer-encoding properly on IO uploads" do
- lambda { subject.put(204, subject.object_path('nethttp', 'test-file'), file, {"Content-Type" => "text/plain"}) }.should_not raise_error
- lambda { subject.put(204, subject.object_path('nethttp', 'test-sized'), sized, {"Content-Type" => "text/plain"}) }.should_not raise_error
- lambda { subject.put(204, subject.object_path('nethttp', 'test-sizeless'), sizeless, {"Content-Type" => "text/plain"}) }.should_not raise_error
+ shared_examples "IO uploads" do |io|
+ it "should upload without error" do
+ lambda do
+ Timeout::timeout(2) do
+ subject.put(
+ 204,
+ subject.object_path('nethttp', 'test-io'),
+ io,
+ {'Content-Type' => 'text/plain'}
+ )
+ end
+ end.should_not raise_error
+ end
+ end
+
+ context "File" do
+ include_examples "IO uploads", File.open(__FILE__)
+ end
+ context "Sized reader" do
+ include_examples "IO uploads", StringIO.new(%w{foo bar baz}.join)
+ end
+ context "Sizeless reader" do
+ include_examples "IO uploads", SizelessReader.new(%w{foo bar baz})
end
end
end