OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / thin-1.2.11-x86-mswin32 / spec / backends / swiftiply_client_spec.rb
1 require File.dirname(__FILE__) + '/../spec_helper'
2
3 describe Backends::SwiftiplyClient do
4   before do
5     @backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
6     @backend.server = mock('server', :null_object => true)
7   end
8   
9   it "should connect" do
10     EventMachine.run do
11       @backend.connect
12       EventMachine.stop
13     end
14   end
15   
16   it "should disconnect" do
17     EventMachine.run do
18       @backend.connect
19       @backend.disconnect
20       EventMachine.stop
21     end
22   end
23 end
24
25 describe SwiftiplyConnection do
26   before do
27     @connection = SwiftiplyConnection.new(nil)
28     @connection.backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
29     @connection.backend.server = mock('server', :null_object => true)
30   end
31   
32   it do
33     @connection.should be_persistent
34   end
35   
36   it "should send handshake on connection_completed" do
37     @connection.should_receive(:send_data).with('swiftclient000000000d0500')
38     @connection.connection_completed
39   end
40   
41   it "should reconnect on unbind" do
42     @connection.backend.stub!(:running?).and_return(true)
43     @connection.stub!(:rand).and_return(0) # Make sure we don't wait
44     
45     @connection.should_receive(:reconnect).with('0.0.0.0', 3333)
46     
47     EventMachine.run do
48       @connection.unbind
49       EventMachine.add_timer(0) { EventMachine.stop }      
50     end
51   end
52   
53   it "should not reconnect when not running" do
54     @connection.backend.stub!(:running?).and_return(false)
55     EventMachine.should_not_receive(:add_timer)
56     @connection.unbind
57   end
58   
59   it "should have a host_ip" do
60     @connection.send(:host_ip).should == [0, 0, 0, 0]
61   end
62   
63   it "should generate swiftiply_handshake based on key" do
64     @connection.send(:swiftiply_handshake, 'key').should == 'swiftclient000000000d0503key'
65   end
66 end