From: Jake Farrell Date: Mon, 1 Oct 2012 18:42:23 +0000 (+0000) Subject: THRIFT-1645: Replace Object#tee with more conventional Object#tap in specs X-Git-Tag: 0.9.1~297 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5d6bd5a606b4cd1f77c65d75888e8424ed22d912;p=common%2Fthrift.git 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 7079b948..f8ffe8a8 100644 --- a/lib/rb/spec/client_spec.rb +++ b/lib/rb/spec/client_spec.rb @@ -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 diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb index b5962793..0890a8bc 100644 --- a/lib/rb/spec/http_client_spec.rb +++ b/lib/rb/spec/http_client_spec.rb @@ -36,10 +36,10 @@ describe 'Thrift::HTTPClientTransport' do @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' do @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 643630f7..fa11b35f 100644 --- a/lib/rb/spec/mongrel_http_server_spec.rb +++ b/lib/rb/spec/mongrel_http_server_spec.rb @@ -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 diff --git a/lib/rb/spec/processor_spec.rb b/lib/rb/spec/processor_spec.rb index ef3bc85b..989f5cca 100644 --- a/lib/rb/spec/processor_spec.rb +++ b/lib/rb/spec/processor_spec.rb @@ -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("#").tee do |args| + args = 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 9701c7cc..8664b664 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 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext]) 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