socky 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +9 -0
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/lib/socky.rb +12 -0
- data/lib/socky/connection.rb +49 -14
- data/lib/socky/connection/authentication.rb +27 -7
- data/lib/socky/connection/finders.rb +54 -43
- data/lib/socky/message.rb +30 -12
- data/lib/socky/misc.rb +22 -0
- data/lib/socky/net_request.rb +5 -0
- data/lib/socky/options.rb +18 -7
- data/lib/socky/options/config.rb +20 -14
- data/lib/socky/options/parser.rb +5 -0
- data/lib/socky/runner.rb +29 -18
- data/spec/em-websocket_spec.rb +3 -4
- data/spec/socky/connection/authentication_spec.rb +27 -16
- data/spec/socky/connection/finders_spec.rb +44 -44
- data/spec/socky/connection_spec.rb +5 -5
- data/spec/socky/message_spec.rb +43 -76
- data/spec/socky/net_request_spec.rb +0 -1
- data/spec/socky/runner_spec.rb +7 -3
- data/spec/{stallion.rb → support/stallion.rb} +0 -0
- metadata +21 -7
@@ -103,7 +103,7 @@ describe Socky::Connection do
|
|
103
103
|
it "#send_data should send message by socket in json format" do
|
104
104
|
@connection.socket.stub!(:send)
|
105
105
|
@connection.socket.should_receive(:send).with({:test => "abstract"}.to_json)
|
106
|
-
@connection.send_data
|
106
|
+
@connection.send(:send_data, {:test => "abstract"})
|
107
107
|
end
|
108
108
|
it "#disconnect should close connection after writing" do
|
109
109
|
@connection.socket.stub!(:close_connection_after_writing)
|
@@ -113,7 +113,7 @@ describe Socky::Connection do
|
|
113
113
|
context "#add_to_pool" do
|
114
114
|
it "should add self to class connection list if self isn't already on list or self isn't admin" do
|
115
115
|
@connection.stub!(:admin).and_return(false)
|
116
|
-
@connection.add_to_pool
|
116
|
+
@connection.send(:add_to_pool)
|
117
117
|
described_class.connections.should include(@connection)
|
118
118
|
described_class.connections.should have(1).item
|
119
119
|
end
|
@@ -121,20 +121,20 @@ describe Socky::Connection do
|
|
121
121
|
described_class.connections << @connection
|
122
122
|
described_class.connections.should have(1).item
|
123
123
|
@connection.stub!(:admin).and_return(false)
|
124
|
-
@connection.add_to_pool
|
124
|
+
@connection.send(:add_to_pool)
|
125
125
|
described_class.connections.should include(@connection)
|
126
126
|
described_class.connections.should have(1).item
|
127
127
|
end
|
128
128
|
it "should not add self to class connection list if self is admin" do
|
129
129
|
@connection.stub!(:admin).and_return(true)
|
130
|
-
@connection.add_to_pool
|
130
|
+
@connection.send(:add_to_pool)
|
131
131
|
described_class.connections.should_not include(@connection)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
it "#remove_from_pool should delete self from class connection list" do
|
135
135
|
described_class.connections << @connection
|
136
136
|
described_class.connections.should have(1).item
|
137
|
-
@connection.remove_from_pool
|
137
|
+
@connection.send(:remove_from_pool)
|
138
138
|
described_class.connections.should_not include(@connection)
|
139
139
|
described_class.connections.should have(0).items
|
140
140
|
end
|
data/spec/socky/message_spec.rb
CHANGED
@@ -47,89 +47,56 @@ describe Socky::Message do
|
|
47
47
|
context "instance" do
|
48
48
|
before(:each) { @message = described_class.new(@connection, {}.to_json) }
|
49
49
|
context "#process" do
|
50
|
-
|
51
|
-
@message.stub!(:
|
52
|
-
@message.stub!(:broadcast)
|
53
|
-
@message.should_receive(:broadcast)
|
54
|
-
@message.process
|
55
|
-
end
|
56
|
-
it "should not distinguish between string and symbol in command" do
|
57
|
-
@message.stub!(:params).and_return({:command => 'broadcast'})
|
58
|
-
@message.stub!(:broadcast)
|
59
|
-
@message.should_receive(:broadcast)
|
60
|
-
@message.process
|
61
|
-
end
|
62
|
-
it "should call #query if message command is :query" do
|
63
|
-
@message.stub!(:params).and_return({:command => :query})
|
64
|
-
@message.stub!(:query)
|
65
|
-
@message.should_receive(:query)
|
66
|
-
@message.process
|
50
|
+
before(:each) do
|
51
|
+
@message.stub!(:send_message)
|
67
52
|
end
|
68
53
|
it "should raise error if message command is nil" do
|
69
54
|
@message.stub!(:params).and_return({:command => nil})
|
70
|
-
lambda {@message.process}.should raise_error
|
55
|
+
lambda {@message.process}.should raise_error(Socky::SockyError, "unknown command")
|
71
56
|
end
|
72
57
|
it "should raise error if message command is neither :broadcast nor :query" do
|
73
|
-
@message.stub!(:params).and_return({:command =>
|
74
|
-
lambda {@message.process}.should raise_error
|
75
|
-
end
|
76
|
-
end
|
77
|
-
context "#broadcast" do
|
78
|
-
it "should select target connections basing on params" do
|
79
|
-
@message.stub!(:params).and_return({:some => :abstract})
|
80
|
-
@message.stub!(:send_message)
|
81
|
-
Socky::Connection.should_receive(:find).with({:some => :abstract})
|
82
|
-
@message.broadcast
|
83
|
-
end
|
84
|
-
it "should call #send_message with message body and connection list" do
|
85
|
-
@message.stub!(:params).and_return({:body => "some message"})
|
86
|
-
Socky::Connection.stub!(:find).and_return(["first","second"])
|
87
|
-
@message.should_receive(:send_message).with("some message", ["first", "second"])
|
88
|
-
@message.broadcast
|
89
|
-
end
|
90
|
-
end
|
91
|
-
context "#query" do
|
92
|
-
it "should call #query_show_connections if message type is :show_connections" do
|
93
|
-
@message.stub!(:params).and_return({:type => :show_connections})
|
94
|
-
@message.stub!(:query_show_connections)
|
95
|
-
@message.should_receive(:query_show_connections)
|
96
|
-
@message.query
|
58
|
+
@message.stub!(:params).and_return({:command => :invalid})
|
59
|
+
lambda {@message.process}.should raise_error(Socky::SockyError, "unknown command")
|
97
60
|
end
|
98
|
-
it "should not distinguish between string and symbol in
|
99
|
-
@message.stub!(:params).and_return({:
|
100
|
-
@message.
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
61
|
+
it "should not distinguish between string and symbol in command" do
|
62
|
+
@message.stub!(:params).and_return({:command => 'broadcast'})
|
63
|
+
lambda {@message.process}.should_not raise_error(Socky::SockyError, "unknown command")
|
64
|
+
end
|
65
|
+
context ":broadcast" do
|
66
|
+
it "should select target connections basing on params" do
|
67
|
+
@message.stub!(:params).and_return({:command => :broadcast, :some => :abstract})
|
68
|
+
Socky::Connection.should_receive(:find).with(:some => :abstract)
|
69
|
+
@message.process
|
70
|
+
end
|
71
|
+
it "should send_message with message body and connection list" do
|
72
|
+
@message.stub!(:params).and_return({:command => :broadcast, :body => "some message"})
|
73
|
+
Socky::Connection.stub!(:find).and_return(["first","second"])
|
74
|
+
@message.should_receive(:send_message).with("some message", ["first", "second"])
|
75
|
+
@message.process
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context ":query" do
|
79
|
+
it "should raise error if query type is nil" do
|
80
|
+
@message.stub!(:params).and_return(:command => :query, :type => nil)
|
81
|
+
lambda{ @message.process }.should raise_error(Socky::SockyError, "unknown query type")
|
82
|
+
end
|
83
|
+
it "should raise error if query type is invalid" do
|
84
|
+
@message.stub!(:params).and_return(:command => :query, :type => :invalid)
|
85
|
+
lambda{ @message.process }.should raise_error(Socky::SockyError, "unknown query type")
|
86
|
+
end
|
87
|
+
it "should not distinguish between string and symbol in command" do
|
88
|
+
@message.stub!(:params).and_return({:command => :query, :type => "show_connections"})
|
89
|
+
lambda {@message.process}.should_not raise_error(Socky::SockyError, "unknown query type")
|
90
|
+
end
|
91
|
+
context "=> :show_connections" do
|
92
|
+
it "should return current connection list to creator" do
|
93
|
+
@message.stub!(:params).and_return(:command => :query, :type => :show_connections)
|
94
|
+
Socky::Connection.stub!(:find_all).and_return(["find results"])
|
95
|
+
@connection.should_receive(:send_message).with(["find results"])
|
96
|
+
@message.process
|
97
|
+
end
|
98
|
+
end
|
131
99
|
end
|
132
100
|
end
|
133
|
-
|
134
101
|
end
|
135
102
|
end
|
data/spec/socky/runner_spec.rb
CHANGED
@@ -30,9 +30,13 @@ describe Socky::Runner do
|
|
30
30
|
end
|
31
31
|
context "#new" do
|
32
32
|
it "should prepare options from args" do
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
begin
|
34
|
+
described_class.new(["-c", File.dirname(__FILE__) + "/../files/default.yml"])
|
35
|
+
Socky.options.class.should eql(Hash)
|
36
|
+
Socky.options.should_not be_empty
|
37
|
+
ensure
|
38
|
+
Socky.options = nil
|
39
|
+
end
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernard Potocki
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-03 00:00:00 +02:00
|
19
19
|
default_executable: socky
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,6 +48,20 @@ dependencies:
|
|
48
48
|
version: "0"
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: json
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
51
65
|
description: Socky is a WebSocket server and client for Ruby on Rails
|
52
66
|
email: b.potocki@imanel.org
|
53
67
|
executables:
|
@@ -89,7 +103,7 @@ files:
|
|
89
103
|
- spec/socky/runner_spec.rb
|
90
104
|
- spec/socky_spec.rb
|
91
105
|
- spec/spec_helper.rb
|
92
|
-
- spec/stallion.rb
|
106
|
+
- spec/support/stallion.rb
|
93
107
|
has_rdoc: true
|
94
108
|
homepage: http://github.com/imanel/socky_gem
|
95
109
|
licenses: []
|
@@ -138,4 +152,4 @@ test_files:
|
|
138
152
|
- spec/socky/runner_spec.rb
|
139
153
|
- spec/socky_spec.rb
|
140
154
|
- spec/spec_helper.rb
|
141
|
-
- spec/stallion.rb
|
155
|
+
- spec/support/stallion.rb
|