lib/saorin/test.rb in saorin-0.5.0 vs lib/saorin/test.rb in saorin-0.6.0
- old
+ new
@@ -76,10 +76,14 @@
def test_notify(*args)
@client.notify *args
end
+ def test_batch
+ @client.batch
+ end
+
shared_context 'setup rpc server client' do |options|
before(:all) do
create_test_server options[:server] || {}
create_test_client options[:client] || {}
end
@@ -87,40 +91,105 @@
shutdown_test_server
end
end
shared_examples 'rpc communicatable' do
- it 'string' do
- value = '123'
- test_call('identity', value).should eq value
- end
+ describe '#call' do
+ it 'string' do
+ v = '123'
+ expect(test_call('identity', v)).to eq v
+ end
- it 'number' do
- value = 123
- test_call('identity', value).should eq value
- end
+ it 'number' do
+ v = 123
+ expect(test_call('identity', v)).to eq v
+ end
- it 'array' do
- value = [1, 2, 3]
- test_call('identity', value).should eq value
- end
+ it 'array' do
+ v = [1, 2, 3]
+ expect(test_call('identity', v)).to eq v
+ end
- it 'hash' do
- value = {'foo' => 1, 'bar' => 2}
- test_call('identity', value).should eq value
- end
+ it 'hash' do
+ v = {'foo' => 1, 'bar' => 2}
+ expect(test_call('identity', v)).to eq v
+ end
- it 'nil' do
- value = nil
- test_call('identity', value).should eq value
+ it 'nil' do
+ v = nil
+ expect(test_call('identity', v)).to eq v
+ end
+
+ it 'not found' do
+ expect { test_call('xx') }.to raise_error MethodNotFound
+ end
+
+ it 'invalid params' do
+ expect { test_call('identity', 1, 2, 3, 4, 5) }.to raise_error InvalidParams
+ end
end
- it 'not found' do
- lambda { test_call('xxx') }.should raise_error MethodNotFound
+ describe '#notify' do
+ it 'string' do
+ v = '123'
+ expect(test_notify('identity', v)).to eq nil
+ end
+
+ it 'not found' do
+ expect(test_notify('xxx')).to eq nil
+ end
+
+ it 'invalid params' do
+ expect(test_notify('identity', 1, 2, 3, 4, 5)).to eq nil
+ end
end
- it 'invalid params' do
- lambda { test_call('identity', 1, 2, 3, 4, 5) }.should raise_error InvalidParams
+ describe '#batch' do
+ it 'batch call' do
+ b = test_batch
+ b.call 'identity', 1
+ b.call 'identity', '2'
+ b.call 'identity', [3]
+ b.call 'xxx'
+
+ ret = b.apply
+ expect(ret).to have(4).items
+ expect(ret[0]).to eq 1
+ expect(ret[1]).to eq '2'
+ expect(ret[2]).to eq [3]
+ expect(ret[3]).to be_instance_of MethodNotFound
+ end
+
+ it 'batch call with notify' do
+ b = test_batch
+ b.call 'identity', 1
+ b.notify 'identity', '2'
+ b.call 'identity', [3]
+ b.notify 'xxx'
+
+ ret = b.apply
+ expect(ret).to have(2).items
+ expect(ret[0]).to eq 1
+ expect(ret[1]).to eq [3]
+ end
+
+ it 'all notify' do
+ b = test_batch
+ b.notify 'identity', 1
+ b.notify 'identity', '2'
+ b.notify 'identity', [3]
+ b.notify 'xxx'
+
+ ret = b.apply
+ expect(ret).to have(0).items
+ end
+
+ it 'empty' do
+ b = test_batch
+
+ ret = b.apply
+ expect(ret).to have(0).items
+ end
end
end
end
end