jstp 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jstp/api.rb +4 -0
- data/lib/jstp/connector.rb +7 -1
- data/lib/jstp/version.rb +1 -1
- data/spec/jstp/api_spec.rb +16 -1
- data/spec/jstp/connector_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/lib/jstp/api.rb
CHANGED
data/lib/jstp/connector.rb
CHANGED
@@ -5,6 +5,12 @@ module JSTP
|
|
5
5
|
class Connector
|
6
6
|
include Singleton
|
7
7
|
|
8
|
+
attr_accessor :port
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@port = 33333
|
12
|
+
end
|
13
|
+
|
8
14
|
# Discovers the server and sends the message
|
9
15
|
# @param [Hash/Array] message
|
10
16
|
def dispatch message
|
@@ -23,7 +29,7 @@ module JSTP
|
|
23
29
|
|
24
30
|
# Sets up the server to be executed within an EventMachine reactor
|
25
31
|
def server
|
26
|
-
::EventMachine::WebSocket.start host: "0.0.0.0", port:
|
32
|
+
::EventMachine::WebSocket.start host: "0.0.0.0", port: @port, &JSTP::Server
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/jstp/version.rb
CHANGED
data/spec/jstp/api_spec.rb
CHANGED
@@ -36,6 +36,21 @@ describe JSTP::API do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#port' do
|
39
|
-
it 'should configure the port number'
|
39
|
+
it 'should configure the port number' do
|
40
|
+
pending "This is working, but it's untesteable because of Reactor pattern"
|
41
|
+
message = {
|
42
|
+
"resource" => ["localhost"]
|
43
|
+
}
|
44
|
+
o = Object.new
|
45
|
+
o.extend JSTP::API
|
46
|
+
o.port 3000
|
47
|
+
|
48
|
+
::EventMachine::WebSocket.should_receive(:start)
|
49
|
+
.with(host: "0.0.0.0", port: 3000)
|
50
|
+
|
51
|
+
o.dispatch do
|
52
|
+
"lala"
|
53
|
+
end
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
data/spec/jstp/connector_spec.rb
CHANGED
@@ -70,6 +70,10 @@ describe JSTP::Connector do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe '#server' do
|
73
|
+
before do
|
74
|
+
JSTP::Connector.instance.port = 33333
|
75
|
+
end
|
76
|
+
|
73
77
|
it 'should start a websocket server in 33333' do
|
74
78
|
JSTP::Server.should_receive :call
|
75
79
|
EventMachine::WebSocket.should_receive(:start)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require 'jstp'
|
2
|
+
require 'jstp'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jstp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-01-
|
14
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: em-websocket
|