jstp 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/jstp.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
10
10
 
11
11
  gem.add_dependency 'em-websocket'
12
12
  gem.add_dependency 'em-websocket-client'
13
+ gem.add_dependency 'discoverer'
13
14
 
14
15
  gem.add_development_dependency 'rspec'
15
16
 
@@ -18,5 +19,5 @@ Gem::Specification.new do |gem|
18
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
20
  gem.name = "jstp"
20
21
  gem.require_paths = ["lib"]
21
- gem.version = Jstp::VERSION
22
+ gem.version = JSTP::VERSION
22
23
  end
data/lib/jstp.rb CHANGED
@@ -3,13 +3,16 @@ require 'singleton'
3
3
  require 'em-websocket'
4
4
  require 'em-websocket-client'
5
5
  require 'json'
6
+ require 'discoverer'
7
+
8
+ require 'jstp/web_socket'
9
+ require 'jstp/tcp'
6
10
 
7
- require 'jstp/event/on_message'
8
- require 'jstp/connector'
9
11
  require 'jstp/api'
10
- require 'jstp/registry'
11
- require 'jstp/server'
12
- require 'jstp/event_machine'
12
+ require 'jstp/connector'
13
+
14
+ require 'writer/jstp/connector'
15
+ require 'reader/jstp/connector'
13
16
 
14
17
  class << self
15
18
  include JSTP::API
data/lib/jstp/api.rb CHANGED
@@ -3,16 +3,19 @@ module JSTP
3
3
  module API
4
4
  def dispatch *args, &block
5
5
  if args.empty? and block
6
- JSTP::Registry.instance.set block
7
-
8
- ::EventMachine.run &JSTP::EventMachine
6
+ Connector.instance.block = block
7
+ Connector.instance.from.send Connector.instance.strategy
9
8
  else
10
- Connector.instance.dispatch args.first
9
+ Connector.instance.to.send Connector.instance.strategy, args.first
11
10
  end
12
11
  end
13
12
 
14
13
  def port number
15
14
  Connector.instance.port = number
16
15
  end
16
+
17
+ def strategy symbol
18
+ Connector.instance.strategy = symbol
19
+ end
17
20
  end
18
21
  end
@@ -4,32 +4,14 @@ module JSTP
4
4
  # Handles the connection functionality for this JSTP reference implementation
5
5
  class Connector
6
6
  include Singleton
7
+ include Discoverer::Writer
8
+ include Discoverer::Reader
7
9
 
8
- attr_accessor :port
10
+ attr_accessor :port, :strategy, :block
9
11
 
10
12
  def initialize
11
13
  @port = 33333
12
- end
13
-
14
- # Discovers the server and sends the message
15
- # @param [Hash/Array] message
16
- def dispatch message
17
- this_client = client(message["resource"])
18
- this_client.callback do
19
- this_client.send_msg message.to_json
20
- end
21
- end
22
-
23
- # Access to the client pool
24
- # @param [Array] the resource data
25
- # @return [EventMachine::WebSocketClient] the client for the address
26
- def client resource
27
- ::EventMachine::WebSocketClient.connect "ws://#{resource.first}:33333/#{resource[1..-1].join('/')}"
28
- end
29
-
30
- # Sets up the server to be executed within an EventMachine reactor
31
- def server
32
- ::EventMachine::WebSocket.start host: "0.0.0.0", port: @port, &JSTP::Server
14
+ @strategy = :tcp
33
15
  end
34
16
  end
35
17
  end
data/lib/jstp/tcp.rb ADDED
@@ -0,0 +1,5 @@
1
+ module JSTP
2
+ class TCP
3
+ include Singleton
4
+ end
5
+ end
data/lib/jstp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
- module Jstp
3
- VERSION = "0.1.0"
2
+ module JSTP
3
+ VERSION = "0.2.0"
4
4
  end
@@ -0,0 +1,30 @@
1
+ module JSTP
2
+ class WebSocket
3
+ include Singleton
4
+
5
+ def server_setup
6
+ @server_setup ||= proc { |server|
7
+ server.onmessage &WebSocket.instance.event_on_message
8
+ }
9
+ end
10
+
11
+ def event_machine
12
+ @event_machine ||= proc {
13
+ ::EM::WebSocket.start host: "0.0.0.0",
14
+ port: Connector.instance.port,
15
+ &WebSocket.instance.server_setup
16
+ }
17
+ end
18
+
19
+ def event_on_message
20
+ @event_on_message ||= proc { |message|
21
+ Connector.instance.block.call JSON.parse message
22
+ }
23
+ end
24
+
25
+ def client resource
26
+ ::EM::WebSocketClient
27
+ .connect "ws://#{resource.first}:33333/#{resource[1..-1].join('/')}"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ module Reader
2
+ module JSTP
3
+ class Connector
4
+ attr_accessor :source
5
+
6
+ def initialize the_source
7
+ @source = the_source
8
+ end
9
+
10
+ # Start the server with the websocket strategy
11
+ def websocket
12
+ ::EventMachine.run &::JSTP::WebSocket.instance.event_machine
13
+ end
14
+
15
+ # Start the server with the TCP strategy
16
+ def tcp
17
+ @server = TCPServer.open @source.port
18
+ loop {
19
+ Thread.start(@server.accept) { |client|
20
+ @source.block.call JSON.parse client.gets
21
+ }
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module Writer
2
+ module JSTP
3
+ class Connector
4
+ attr_accessor :source
5
+
6
+ def initialize source
7
+ @source = source
8
+ end
9
+
10
+ # Dispatch this applying the websocket strategy
11
+ def websocket message
12
+ this_client = ::JSTP::WebSocket.instance
13
+ .client message["resource"]
14
+ json = message.to_json
15
+ this_client.callback do
16
+ this_client.send_msg json
17
+ end
18
+ end
19
+
20
+ # Dispatch thid applying the TCP strategy
21
+ def tcp message
22
+ client = TCPSocket.open message["resource"].first, @source.port
23
+ client.puts message.to_json
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,42 +2,103 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe JSTP::API do
5
+ describe '#strategy' do
6
+ it 'should set the strategy' do
7
+ o = Object.new
8
+ o.extend JSTP::API
9
+
10
+ o.strategy :websocket
11
+
12
+ JSTP::Connector.instance.strategy.should == :websocket
13
+ end
14
+ end
15
+
5
16
  describe '#dispatch' do
6
- context 'a block is passed' do
7
- it 'should register the block and send JSTP::Server to the EventMachine reactor' do
8
- block = proc {
9
- "lalal"
10
- }
11
-
12
- JSTP::Registry.instance.should_receive(:set)
13
- .with block
14
-
15
- JSTP::EventMachine.should_receive :call
16
- EventMachine.should_receive(:run)
17
- .with &JSTP::EventMachine
18
-
19
- o = Object.new
20
- o.extend JSTP::API
21
- o.dispatch &block
17
+ context 'websocket strategy' do
18
+ before do
19
+ JSTP::Connector.instance.strategy = :websocket
20
+ end
21
+
22
+ context 'a block is passed' do
23
+ it 'should register the block and send JSTP::Server to the EventMachine reactor' do
24
+ block = proc { "lalal" }
25
+ reader = stub 'reader'
26
+
27
+ JSTP::Connector.instance.should_receive(:block=)
28
+ .with block
29
+
30
+ JSTP::Connector.instance.should_receive(:from)
31
+ .and_return reader
32
+ reader.should_receive :websocket
33
+
34
+ o = Object.new
35
+ o.extend JSTP::API
36
+ o.dispatch &block
37
+ end
38
+ end
39
+
40
+ context 'an argument is passed' do
41
+ it 'should dispatch the message via the Connector' do
42
+ message = stub 'message'
43
+ writer = stub 'writer'
44
+
45
+ JSTP::Connector.instance.should_receive(:to)
46
+ .and_return writer
47
+
48
+ writer.should_receive(:websocket)
49
+ .with message
50
+
51
+ o = Object.new
52
+ o.extend JSTP::API
53
+ o.dispatch message
54
+ end
22
55
  end
23
56
  end
24
57
 
25
- context 'an argument is passed' do
26
- it 'should dispatch the message via the Connector' do
27
- message = stub 'message'
28
- JSTP::Connector.instance.should_receive(:dispatch)
29
- .with message
58
+ context 'tcp strategy' do
59
+ before do
60
+ JSTP::Connector.instance.strategy = :tcp
61
+ end
62
+
63
+ context 'a block is passed' do
64
+ it 'should register the block and send JSTP::Server to the EventMachine reactor' do
65
+ block = proc { "lalal" }
66
+ reader = stub 'reader'
67
+
68
+ JSTP::Connector.instance.should_receive(:block=)
69
+ .with block
70
+
71
+ JSTP::Connector.instance.should_receive(:from)
72
+ .and_return reader
73
+ reader.should_receive :tcp
30
74
 
31
- o = Object.new
32
- o.extend JSTP::API
33
- o.dispatch message
75
+ o = Object.new
76
+ o.extend JSTP::API
77
+ o.dispatch &block
78
+ end
79
+ end
80
+
81
+ context 'an argument is passed' do
82
+ it 'should dispatch the message via the Connector' do
83
+ message = stub 'message'
84
+ writer = stub 'writer'
85
+
86
+ JSTP::Connector.instance.should_receive(:to)
87
+ .and_return writer
88
+
89
+ writer.should_receive(:tcp)
90
+ .with message
91
+
92
+ o = Object.new
93
+ o.extend JSTP::API
94
+ o.dispatch message
95
+ end
34
96
  end
35
97
  end
36
98
  end
37
99
 
38
100
  describe '#port' do
39
101
  it 'should configure the port number' do
40
- pending "This is working, but it's untesteable because of Reactor pattern"
41
102
  message = {
42
103
  "resource" => ["localhost"]
43
104
  }
@@ -45,12 +106,7 @@ describe JSTP::API do
45
106
  o.extend JSTP::API
46
107
  o.port 3000
47
108
 
48
- ::EventMachine::WebSocket.should_receive(:start)
49
- .with(host: "0.0.0.0", port: 3000)
50
-
51
- o.dispatch do
52
- "lala"
53
- end
109
+ JSTP::Connector.instance.port.should == 3000
54
110
  end
55
111
  end
56
112
  end
@@ -6,84 +6,11 @@ describe JSTP::Connector do
6
6
  JSTP::Connector.ancestors.should include Singleton
7
7
  end
8
8
 
9
- describe '#dispatch' do
10
- before do
11
- @message = {
12
- "protocol" => ["JSTP", "0.1"],
13
- "method" => "POST",
14
- "resource" => [
15
- "session.manager",
16
- "User"
17
- ],
18
- "timestamp" => 1357334118,
19
- "token" => 3523902859084057289594,
20
- "referer" => [
21
- "browser",
22
- "Registerer"
23
- ],
24
- "body" => {
25
- "login" => "xavier",
26
- "email" => "xavier@fetcher.com",
27
- "password" => "secret"
28
- }
29
- }
30
-
31
- @web_socket_client = stub 'web socket client'
32
- @message_json = stub 'message json'
33
- end
34
-
35
- it 'should open a websocket to the correct resource in the standard port 33333 and set the callback' do
36
- pending "I'm unable to test this properly since providing a Proc will make me lose scope for the client"
37
- JSTP::Connector.instance.should_receive(:client)
38
- .with(@message["resource"])
39
- .and_return @web_socket_client
40
-
41
- @web_socket_client.should_receive(:callback)
42
-
43
- @web_socket_client.should_receive(:send_msg)
44
- .with(@message_json)
45
- @message.should_receive(:to_json).and_return @message_json
46
-
47
- JSTP::Connector.instance.dispatch @message
48
- end
49
-
50
- it 'should attach the callback to the client so the message is actually delivered!'
9
+ it 'should include a discoverer for Writer' do
10
+ JSTP::Connector.ancestors.should include Discoverer::Writer
51
11
  end
52
12
 
53
- describe '#client' do
54
- context 'there is no connection for that address' do
55
- before do
56
- @web_socket_client = stub 'web socket client'
57
- @resource = ["localhost", "hola", "quetal"]
58
- end
59
-
60
- it 'should initialize the websocket client' do
61
- EventMachine::WebSocketClient.should_receive(:connect)
62
- .with("ws://#{@resource.first}:33333/#{@resource[1..-1].join('/')}")
63
- .and_return @web_socket_client
64
-
65
- JSTP::Connector.instance
66
- .client(@resource)
67
- .should == @web_socket_client
68
- end
69
- end
70
- end
71
-
72
- describe '#server' do
73
- before do
74
- JSTP::Connector.instance.port = 33333
75
- end
76
-
77
- it 'should start a websocket server in 33333' do
78
- JSTP::Server.should_receive :call
79
- EventMachine::WebSocket.should_receive(:start)
80
- .with({ host: '0.0.0.0', port: 33333 }, &JSTP::Server)
81
-
82
- JSTP::Connector.instance.server
83
- end
84
-
85
- it 'should pass the proc JSTP::Server' do
86
- pending "Warning, this isn't actually testing the JSTP::Server, I don't know why"
87
- end
13
+ it 'should include a discoverer for Reader' do
14
+ JSTP::Connector.ancestors.should include Discoverer::Reader
88
15
  end
89
16
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe JSTP::TCP do
4
+ it 'should be a singleton' do
5
+ JSTP::TCP.ancestors.should include Singleton
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe JSTP::WebSocket do
4
+ it 'should be a singleton' do
5
+ JSTP::WebSocket.ancestors.should include Singleton
6
+ end
7
+
8
+ describe '#event_machine' do
9
+ before do
10
+ JSTP::Connector.instance.port = 33333
11
+ end
12
+
13
+ it 'should start a websocket server in 33333' do
14
+ JSTP::WebSocket.instance.server_setup
15
+ .should_receive :call
16
+
17
+ EventMachine::WebSocket.should_receive(:start)
18
+ .with({ host: '0.0.0.0', port: 33333 }, &JSTP::WebSocket.instance.server_setup)
19
+
20
+ JSTP::WebSocket.instance.event_machine.call
21
+ end
22
+ end
23
+
24
+ describe '#server_setup' do
25
+ it 'should set #event_on_message to onmessage' do
26
+ server = stub 'server'
27
+ JSTP::WebSocket.instance.event_on_message.should_receive :call
28
+
29
+ server.should_receive(:onmessage)
30
+ .with &JSTP::WebSocket.instance.event_on_message
31
+
32
+ JSTP::WebSocket.instance.server_setup.call server
33
+ end
34
+ end
35
+
36
+ describe '#event_on_message' do
37
+ it 'should call the registered block with the parsed message' do
38
+ @the_proc = stub 'the proc'
39
+ @message = stub 'message'
40
+ @parsed_message = stub 'parsed message'
41
+
42
+ JSON.should_receive(:parse).with(@message)
43
+ .and_return @parsed_message
44
+
45
+ JSTP::Connector.instance.should_receive(:block)
46
+ .and_return @the_proc
47
+
48
+ @the_proc.should_receive(:call)
49
+ .with @parsed_message
50
+
51
+ JSTP::WebSocket.instance.event_on_message.call @message
52
+ end
53
+ end
54
+
55
+ describe '#client' do
56
+ context 'there is no connection for that address' do
57
+ before do
58
+ @web_socket_client = stub 'web socket client'
59
+ @resource = ["localhost", "hola", "quetal"]
60
+ end
61
+
62
+ it 'should initialize the websocket client' do
63
+ EventMachine::WebSocketClient.should_receive(:connect)
64
+ .with("ws://#{@resource.first}:33333/#{@resource[1..-1].join('/')}")
65
+ .and_return @web_socket_client
66
+
67
+ JSTP::WebSocket.instance
68
+ .client(@resource)
69
+ .should == @web_socket_client
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Reader::JSTP::Connector do
4
+ describe '#websocket' do
5
+ it 'should run EventMachine with the JSTP::EventMachine proc' do
6
+ JSTP::WebSocket.instance.event_machine.should_receive :call
7
+
8
+ EventMachine.should_receive(:run)
9
+ .with &JSTP::WebSocket.instance.event_machine
10
+
11
+ reader = Reader::JSTP::Connector.new stub 'connector'
12
+ reader.websocket
13
+ end
14
+ end
15
+
16
+ describe '#tcp' do
17
+ it 'should create the server and start it' do
18
+ pending 'I still can test infinite loops'
19
+
20
+ tcp_server = stub 'tcp server'
21
+
22
+ TCPServer.should_receive(:open)
23
+ .with(JSTP::Connector.instance.port)
24
+ .and_return tcp_server
25
+
26
+ tcp_server.should_receive(:accept)
27
+
28
+ reader = Reader::JSTP::Connector.new stub 'connector'
29
+ reader.tcp
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Writer::JSTP::Connector do
4
+ describe '#websocket' do
5
+ before do
6
+ @connector = stub 'connector'
7
+ @message = { "resource" => ["lala"] }
8
+ @message_json = stub 'message_json'
9
+ @web_socket_client = stub 'web socket client'
10
+ end
11
+
12
+ it 'should get the client from the pool and set the callback' do
13
+ @writer = Writer::JSTP::Connector.new @connector
14
+
15
+ JSTP::WebSocket.instance.should_receive(:client)
16
+ .with(@message["resource"])
17
+ .and_return @web_socket_client
18
+
19
+ @web_socket_client.should_receive(:callback)
20
+
21
+ @message.should_receive(:to_json).and_return @message_json
22
+
23
+ @writer.websocket @message
24
+ end
25
+
26
+ it 'should send the message from the callback' do
27
+ pending "I'm unable to test this properly since providing a Proc will make me lose scope for the client"
28
+ @writer = Writer::JSTP::Connector.new @connector
29
+
30
+ JSTP::WebSocket.should_receive(:client)
31
+ .with(@message["resource"])
32
+ .and_return @web_socket_client
33
+
34
+ @web_socket_client.should_receive(:callback)
35
+
36
+ @message.should_receive(:to_json).and_return @message_json
37
+ @web_socket_client.should_receive(:send_msg)
38
+ .with(@message_json)
39
+
40
+ @writer.websocket @message
41
+ end
42
+ end
43
+
44
+ describe '#tcp' do
45
+ it 'should get the resource and use it as host, then send the dispatch in JSON' do
46
+ message = stub 'message'
47
+ message_json = stub 'message json'
48
+ resource = stub 'resource'
49
+ hostname = stub 'hostname'
50
+ socket = stub 'socket'
51
+
52
+ message.should_receive(:[]).with("resource")
53
+ .and_return resource
54
+
55
+ resource.should_receive(:first).and_return hostname
56
+
57
+ JSTP::Connector.instance.should_receive(:port).
58
+ and_return 4444
59
+
60
+ TCPSocket.should_receive(:open).with(hostname, 4444)
61
+ .and_return socket
62
+
63
+ message.should_receive(:to_json).and_return message_json
64
+
65
+ socket.should_receive(:puts).with message_json
66
+
67
+ writer = Writer::JSTP::Connector.new ::JSTP::Connector.instance
68
+ writer.tcp message
69
+ end
70
+ end
71
+ end
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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,6 +45,22 @@ dependencies:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: discoverer
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
48
64
  - !ruby/object:Gem::Dependency
49
65
  name: rspec
50
66
  requirement: !ruby/object:Gem::Requirement
@@ -78,18 +94,18 @@ files:
78
94
  - lib/jstp.rb
79
95
  - lib/jstp/api.rb
80
96
  - lib/jstp/connector.rb
81
- - lib/jstp/event/on_message.rb
82
- - lib/jstp/event_machine.rb
83
- - lib/jstp/registry.rb
84
- - lib/jstp/server.rb
97
+ - lib/jstp/tcp.rb
85
98
  - lib/jstp/version.rb
99
+ - lib/jstp/web_socket.rb
100
+ - lib/reader/jstp/connector.rb
101
+ - lib/writer/jstp/connector.rb
86
102
  - spec/jstp/api_spec.rb
87
103
  - spec/jstp/connector_spec.rb
88
- - spec/jstp/event/on_message_spec.rb
89
- - spec/jstp/event_machine_spec.rb
90
- - spec/jstp/registry_spec.rb
91
- - spec/jstp/server_spec.rb
104
+ - spec/jstp/tcp_spec.rb
105
+ - spec/jstp/web_socket_spec.rb
106
+ - spec/reader/jstp/connector_spec.rb
92
107
  - spec/spec_helper.rb
108
+ - spec/writer/jstp/connector_spec.rb
93
109
  homepage: https://github.com/Fetcher/jstp
94
110
  licenses: []
95
111
  post_install_message:
@@ -117,9 +133,9 @@ summary: Reference implementation for the sketch protocol JSTP
117
133
  test_files:
118
134
  - spec/jstp/api_spec.rb
119
135
  - spec/jstp/connector_spec.rb
120
- - spec/jstp/event/on_message_spec.rb
121
- - spec/jstp/event_machine_spec.rb
122
- - spec/jstp/registry_spec.rb
123
- - spec/jstp/server_spec.rb
136
+ - spec/jstp/tcp_spec.rb
137
+ - spec/jstp/web_socket_spec.rb
138
+ - spec/reader/jstp/connector_spec.rb
124
139
  - spec/spec_helper.rb
140
+ - spec/writer/jstp/connector_spec.rb
125
141
  has_rdoc:
@@ -1,8 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module JSTP
3
- module Event
4
- OnMessage = proc { |message|
5
- JSTP::Registry.instance.get.call JSON.parse message
6
- }
7
- end
8
- end
@@ -1,6 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module JSTP
3
- EventMachine = proc {
4
- JSTP::Connector.instance.server
5
- }
6
- end
data/lib/jstp/registry.rb DELETED
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module JSTP
3
- class Registry
4
- include Singleton
5
-
6
- def set block
7
- @block = block
8
- end
9
-
10
- def get
11
- @block
12
- end
13
- end
14
- end
data/lib/jstp/server.rb DELETED
@@ -1,6 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module JSTP
3
- Server = proc { |websocket|
4
- websocket.onmessage &Event::OnMessage
5
- }
6
- end
@@ -1,21 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'JSTP::Event::OnMessage' do
5
- it 'should call the registered block with the parsed message' do
6
- @the_proc = stub 'the proc'
7
- @message = stub 'message'
8
- @parsed_message = stub 'parsed message'
9
-
10
- JSON.should_receive(:parse).with(@message)
11
- .and_return @parsed_message
12
-
13
- JSTP::Registry.instance.should_receive(:get)
14
- .and_return @the_proc
15
-
16
- @the_proc.should_receive(:call)
17
- .with @parsed_message
18
-
19
- JSTP::Event::OnMessage.call @message
20
- end
21
- end
@@ -1,10 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'JSTP::EventMachine' do
5
- it 'should ask the connector to initialize the server' do
6
- JSTP::Connector.instance.should_receive(:server)
7
-
8
- JSTP::EventMachine.call
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe JSTP::Registry do
5
- it 'should be a Singleton' do
6
- JSTP::Registry.ancestors.should include Singleton
7
- end
8
-
9
- describe '#get' do
10
- it 'should return the registered block' do
11
- @data = stub 'data'
12
- JSTP::Registry.instance.set @data
13
- JSTP::Registry.instance.get.should == @data
14
- end
15
- end
16
-
17
- describe '#set' do
18
- it 'should set the block in the registry' do
19
- @data = stub 'data'
20
- JSTP::Registry.instance.set @data
21
- JSTP::Registry.instance.get.should == @data
22
- end
23
- end
24
- end
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe 'JSTP::Server' do
5
- it 'should set JSTP::Event::OnMessage to onmessage' do
6
- server = stub 'server'
7
- JSTP::Event::OnMessage.stub :call
8
-
9
- server.should_receive(:onmessage)
10
- .with(&JSTP::Event::OnMessage)
11
-
12
- JSTP::Server.call server
13
- end
14
- end