spec/unit/client_spec.rb in msgpack-rpc-0.5.2 vs spec/unit/client_spec.rb in msgpack-rpc-0.5.3
- old
+ new
@@ -1,7 +1,8 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper.rb')
-require File.join(File.expand_path(File.dirname(__FILE__)), 'my_server.rb')
+require 'spec_helper'
+require_relative './my_server'
+
include MyServerTest
describe 'MessagePack::RPC::Client test' do
before(:each)do
@svr,@client = start_server
@@ -21,38 +22,42 @@
@client.call(:sum,1,2).should equal 3
end
it 'should return "ok" and "3" when you call with call_async' do
req1 = @client.call_async(:hello)
- req2 = @client.call_async(:sum,1,2)
+ req2 = @client.call_async(:sum, 1, 2)
req1.join
req1.result.should include("ok")
req1.error.should be_nil
req2.join
req2.result.should equal 3
req2.error.should be_nil
end
it 'should return "ok" when you set callback(:hello)' do
- @client.callback(:hello) do |error, result|
+ req = @client.callback(:hello) do |error, result|
result.should include("ok")
error.should be_nil
end
+ req.join
end
it 'should return "3" when you set callback(:sum)' do
- @client.callback(:sum) do |error, result|
- result.shouble equal 3
+ req = @client.callback(:sum, 1, 2) do |error, result|
+ result.should equal 3
error.should be_nil
end
+ req.join
end
it 'should return nil values when you call notify' do
- @client.notify(:hello).should be_nil
- @client.notify(:sum,1,2).should be_nil
+ @client.call(:count).should eq 0
+ @client.notify(:increase_count).should be_nil
+ sleep 0.5
+ @client.call(:count).should eq 1
end
it 'should return error when you call private method' do
lambda{@client.call(:hidden)}.should raise_error(MessagePack::RPC::RemoteError)
end
@@ -86,20 +91,20 @@
end
describe "MessagePack::RPC::TimeoutError test" do
before(:each)do
- @client = start_client
+ @client = start_client(PortHelper.find_port)
@lsock = TCPServer.new("0.0.0.0",@client.port)
@client.timeout = 1
end
it 'should return MessagePack::RPC::TimoutError' do
lambda{@client.call(:hello)}.should raise_error(MessagePack::RPC::TimeoutError)
- end
+ end
- after(:all)do
+ after(:each)do
@client.close
@lsock.close
end
end
@@ -115,11 +120,9 @@
@cli.timeout = 10
end
it "should return correct values when you use MessagePack::RPC::Loop" do
- count = 0
-
@cli.callback(:hello) do |error, result|
result.should include("ok")
error.should be_nil
end