You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/06/18 03:05:03 UTC

svn commit: r668941 - in /incubator/thrift/trunk/lib/rb/spec: client_spec.rb exception_spec.rb spec_helper.rb

Author: kclark
Date: Tue Jun 17 18:05:03 2008
New Revision: 668941

URL: http://svn.apache.org/viewvc?rev=668941&view=rev
Log:
Spec out Thrift::Client

Added:
    incubator/thrift/trunk/lib/rb/spec/client_spec.rb
Modified:
    incubator/thrift/trunk/lib/rb/spec/exception_spec.rb
    incubator/thrift/trunk/lib/rb/spec/spec_helper.rb

Added: incubator/thrift/trunk/lib/rb/spec/client_spec.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/client_spec.rb?rev=668941&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/client_spec.rb (added)
+++ incubator/thrift/trunk/lib/rb/spec/client_spec.rb Tue Jun 17 18:05:03 2008
@@ -0,0 +1,56 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+class ThriftSpec < Spec::ExampleGroup
+  include Thrift
+
+  class ClientSpec
+    include Thrift::Client
+  end
+
+  before(:each) do
+    @prot = mock("MockProtocol")
+    @client = ClientSpec.new(@prot)
+  end
+
+  describe "Client" do
+    it "should re-use iprot for oprot if not otherwise specified" do
+      @client.instance_variable_get(:'@iprot').should eql(@prot)
+      @client.instance_variable_get(:'@oprot').should eql(@prot)
+    end
+
+    it "should send a test message" do
+      @prot.should_receive(:write_message_begin).with('testMessage', MessageTypes::CALL, 0)
+      mock_args = mock('#<TestMessage_args:mock>')
+      mock_args.should_receive(:foo=).with('foo')
+      mock_args.should_receive(:bar=).with(42)
+      mock_args.should_receive(:write).with(@prot)
+      @prot.should_receive(:write_message_end)
+      @prot.should_receive(:trans) do
+        mock('trans').tee do |trans|
+          trans.should_receive(:flush)
+        end
+      end
+      klass = stub("TestMessage_args", :new => mock_args)
+      @client.send_message('testMessage', klass, :foo => 'foo', :bar => 42)
+    end
+
+    it "should receive a test message" do
+      @prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::CALL, 0]
+      @prot.should_receive(:read_message_end)
+      mock_klass = mock("#<MockClass:mock>")
+      mock_klass.should_receive(:read).with(@prot)
+      @client.receive_message(stub("MockClass", :new => mock_klass))
+    end
+
+    it "should handle received exceptions" do
+      @prot.should_receive(:read_message_begin).and_return [nil, MessageTypes::EXCEPTION, 0]
+      @prot.should_receive(:read_message_end)
+      ApplicationException.should_receive(:new).and_return do
+        StandardError.new.tee do |mock_exc|
+          mock_exc.should_receive(:read).with(@prot)
+        end
+      end
+      lambda { @client.receive_message(nil) }.should raise_error(StandardError)
+    end
+  end
+end

Modified: incubator/thrift/trunk/lib/rb/spec/exception_spec.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/exception_spec.rb?rev=668941&r1=668940&r2=668941&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/exception_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/exception_spec.rb Tue Jun 17 18:05:03 2008
@@ -1,15 +1,15 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
-module Thrift
+class ThriftSpec < Spec::ExampleGroup
+  include Thrift
+
   describe Exception do
     it "should have an accessible message" do
       e = Exception.new("test message")
       e.message.should == "test message"
     end
   end
-end
 
-module Thrift
   describe ApplicationException do
     it "should inherit from Thrift::Exception" do
       ApplicationException.superclass.should == Exception

Modified: incubator/thrift/trunk/lib/rb/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/spec_helper.rb?rev=668941&r1=668940&r2=668941&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/spec_helper.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/spec_helper.rb Tue Jun 17 18:05:03 2008
@@ -2,3 +2,11 @@
 require 'spec'
 
 require File.dirname(__FILE__) + '/../lib/thrift'
+
+class Object
+  # tee is a useful method, so let's let our tests have it
+  def tee(&block)
+    block.call(self)
+    self
+  end
+end