Author: jfarrell
Date: Mon Oct  1 18:42:23 2012
New Revision: 1392509

URL: http://svn.apache.org/viewvc?rev=1392509&view=rev
Log:
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.


Modified:
    thrift/trunk/lib/rb/spec/client_spec.rb
    thrift/trunk/lib/rb/spec/http_client_spec.rb
    thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb
    thrift/trunk/lib/rb/spec/processor_spec.rb
    thrift/trunk/lib/rb/spec/spec_helper.rb

Modified: thrift/trunk/lib/rb/spec/client_spec.rb
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/client_spec.rb?rev=1392509&r1=1392508&r2=1392509&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/client_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/client_spec.rb Mon Oct  1 18:42:23 2012
@@ -44,7 +44,7 @@ describe 'Client' do
       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 @@ describe 'Client' do
       @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

Modified: thrift/trunk/lib/rb/spec/http_client_spec.rb
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/http_client_spec.rb?rev=1392509&r1=1392508&r2=1392509&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/http_client_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/http_client_spec.rb Mon Oct  1 18:42:23 2012
@@ -36,10 +36,10 @@ describe 'Thrift::HTTPClientTransport' d
       @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 @@ describe 'Thrift::HTTPClientTransport' d
 
       @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

Modified: thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb?rev=1392509&r1=1392508&r2=1392509&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb Mon Oct  1 18:42:23 
2012
@@ -28,7 +28,7 @@ describe 'HTTPServer' do
       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 @@ describe 'HTTPServer' do
       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 @@ describe 'HTTPServer' do
     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

Modified: thrift/trunk/lib/rb/spec/processor_spec.rb
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/processor_spec.rb?rev=1392509&r1=1392508&r2=1392509&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/processor_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/processor_spec.rb Mon Oct  1 18:42:23 2012
@@ -33,7 +33,7 @@ describe 'Processor' do
 
     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 @@ describe 'Processor' do
 
     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

Modified: thrift/trunk/lib/rb/spec/spec_helper.rb
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/spec_helper.rb?rev=1392509&r1=1392508&r2=1392509&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/spec_helper.rb (original)
+++ thrift/trunk/lib/rb/spec/spec_helper.rb Mon Oct  1 18:42:23 2012
@@ -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 @@ $:.unshift File.join(File.dirname(__FILE
 
 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
 


Reply via email to