socky 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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({:test => "abstract"})
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
@@ -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
- it "should call #broadcast if message command is :broadcast" do
51
- @message.stub!(:params).and_return({:command => :broadcast})
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 Socky::SockyError
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 => "invalid"})
74
- lambda {@message.process}.should raise_error Socky::SockyError
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 type" do
99
- @message.stub!(:params).and_return({:type => 'show_connections'})
100
- @message.stub!(:query_show_connections)
101
- @message.should_receive(:query_show_connections)
102
- @message.query
103
- end
104
- it "should raise error if message type is nil" do
105
- @message.stub!(:params).and_return({:type => nil})
106
- lambda{ @message.query }.should raise_error Socky::SockyError
107
- end
108
- it "should raise error if message type is not :show_connections" do
109
- @message.stub!(:params).and_return({:type => "invalid"})
110
- lambda{ @message.query }.should raise_error Socky::SockyError
111
- end
112
- end
113
- context "#query_show_connections" do
114
- before(:each) do
115
- Socky::Connection.stub!(:find_all).and_return("find results")
116
- @message.stub!(:respond)
117
- end
118
- it "should ask for all connections" do
119
- Socky::Connection.should_receive(:find_all)
120
- @message.query_show_connections
121
- end
122
- it "should respond current connection list" do
123
- @message.should_receive(:respond).with("find results")
124
- @message.query_show_connections
125
- end
126
- end
127
- context "#respond" do
128
- it "should call creator #send_message" do
129
- @connection.should_receive(:send_message)
130
- @message.respond({:test => true})
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
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'stallion'
3
2
 
4
3
  describe Socky::NetRequest do
5
4
 
@@ -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
- Socky::Options.stub!(:prepare)
34
- Socky::Options.should_receive(:prepare).with("some args")
35
- described_class.new("some args")
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
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: 29
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
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-09-23 00:00:00 +02:00
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