THRIFT-1645: Replace Object#tee with more conventional Object#tap in specs
Client: rb
Patch: Nathan Beyer
The spec_helper.rb defines an Object#tee method, which is functionally equivalent to Object#tap. Object#tap was added to Ruby 1.9 and to 1.8.7.
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1392509 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/client_spec.rb b/lib/rb/spec/client_spec.rb
index 7079b94..f8ffe8a 100644
--- a/lib/rb/spec/client_spec.rb
+++ b/lib/rb/spec/client_spec.rb
@@ -44,7 +44,7 @@
mock_args.should_receive(:write).with(@prot)
@prot.should_receive(:write_message_end)
@prot.should_receive(:trans) do
- mock('trans').tee do |trans|
+ mock('trans').tap do |trans|
trans.should_receive(:flush)
end
end
@@ -77,7 +77,7 @@
@prot.should_receive(:read_message_begin).and_return [nil, Thrift::MessageTypes::EXCEPTION, 0]
@prot.should_receive(:read_message_end)
Thrift::ApplicationException.should_receive(:new).and_return do
- StandardError.new.tee do |mock_exc|
+ StandardError.new.tap do |mock_exc|
mock_exc.should_receive(:read).with(@prot)
end
end
diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb
index b596279..0890a8b 100644
--- a/lib/rb/spec/http_client_spec.rb
+++ b/lib/rb/spec/http_client_spec.rb
@@ -36,10 +36,10 @@
@client.write "a test"
@client.write " frame"
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
- mock("Net::HTTP").tee do |http|
+ mock("Net::HTTP").tap do |http|
http.should_receive(:use_ssl=).with(false)
http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return do
- mock("Net::HTTPOK").tee do |response|
+ mock("Net::HTTPOK").tap do |response|
response.should_receive(:body).and_return "data"
end
end
@@ -56,10 +56,10 @@
@client.add_headers(custom_headers)
Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
- mock("Net::HTTP").tee do |http|
+ mock("Net::HTTP").tap do |http|
http.should_receive(:use_ssl=).with(false)
http.should_receive(:post).with("/path/to/service?param=value", "test", headers).and_return do
- mock("Net::HTTPOK").tee do |response|
+ mock("Net::HTTPOK").tap do |response|
response.should_receive(:body).and_return "data"
end
end
diff --git a/lib/rb/spec/mongrel_http_server_spec.rb b/lib/rb/spec/mongrel_http_server_spec.rb
index 643630f..fa11b35 100644
--- a/lib/rb/spec/mongrel_http_server_spec.rb
+++ b/lib/rb/spec/mongrel_http_server_spec.rb
@@ -28,7 +28,7 @@
mock_proc = mock("Processor")
Thrift::BinaryProtocolFactory.should_receive(:new).and_return(mock_factory)
Mongrel::HttpServer.should_receive(:new).with("0.0.0.0", 80).and_return do
- mock("Mongrel::HttpServer").tee do |mock|
+ mock("Mongrel::HttpServer").tap do |mock|
handler = mock("Handler")
Thrift::MongrelHTTPServer::Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
mock.should_receive(:register).with("/", handler)
@@ -41,7 +41,7 @@
mock_proc = mock("Processor")
mock_factory = mock("ProtocolFactory")
Mongrel::HttpServer.should_receive(:new).with("1.2.3.4", 1234).and_return do
- mock("Mongrel::HttpServer").tee do |mock|
+ mock("Mongrel::HttpServer").tap do |mock|
handler = mock("Handler")
Thrift::MongrelHTTPServer::Handler.should_receive(:new).with(mock_proc, mock_factory).and_return(handler)
mock.should_receive(:register).with("/foo", handler)
@@ -54,11 +54,11 @@
it "should serve using Mongrel::HttpServer" do
Thrift::BinaryProtocolFactory.stub!(:new)
Mongrel::HttpServer.should_receive(:new).and_return do
- mock("Mongrel::HttpServer").tee do |mock|
+ mock("Mongrel::HttpServer").tap do |mock|
Thrift::MongrelHTTPServer::Handler.stub!(:new)
mock.stub!(:register)
mock.should_receive(:run).and_return do
- mock("Mongrel::HttpServer.run").tee do |runner|
+ mock("Mongrel::HttpServer.run").tap do |runner|
runner.should_receive(:join)
end
end
diff --git a/lib/rb/spec/processor_spec.rb b/lib/rb/spec/processor_spec.rb
index ef3bc85..989f5cc 100644
--- a/lib/rb/spec/processor_spec.rb
+++ b/lib/rb/spec/processor_spec.rb
@@ -33,7 +33,7 @@
def mock_trans(obj)
obj.should_receive(:trans).ordered.and_return do
- mock("trans").tee do |trans|
+ mock("trans").tap do |trans|
trans.should_receive(:flush).ordered
end
end
@@ -60,7 +60,7 @@
it "should pass args off to the args class" do
args_class = mock("MockArgsClass")
- args = mock("#<MockArgsClass:mock>").tee do |args|
+ args = mock("#<MockArgsClass:mock>").tap do |args|
args.should_receive(:read).with(@prot).ordered
end
args_class.should_receive(:new).and_return args
diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb
index 9701c7c..8664b66 100644
--- a/lib/rb/spec/spec_helper.rb
+++ b/lib/rb/spec/spec_helper.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -28,11 +29,13 @@
require 'thrift'
-class Object
- # tee is a useful method, so let's let our tests have it
- def tee(&block)
- block.call(self)
- self
+unless Object.method_defined? :tap
+ # if Object#tap isn't defined, then add it; this should only happen in Ruby < 1.8.7
+ class Object
+ def tap(&block)
+ block.call(self)
+ self
+ end
end
end