Bluebie-legs 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/legs.gemspec +3 -3
- data/test/test_legs.rb +203 -0
- metadata +3 -3
data/legs.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "legs"
|
3
|
-
s.version = "0.6.
|
4
|
-
s.date = "2008-07-
|
3
|
+
s.version = "0.6.2"
|
4
|
+
s.date = "2008-07-17"
|
5
5
|
s.summary = "Simple fun open networking for newbies and quick hacks"
|
6
6
|
s.email = "blue@creativepony.com"
|
7
7
|
s.homepage = "http://github.com/Bluebie/legs"
|
8
8
|
s.description = "Legs is a really simple fun networking library that uses 'json-rpc' formated messages over a tcp connection to really easily built peery or server-clienty sorts of apps, for ruby newbies and hackers to build fun little things."
|
9
9
|
s.has_rdoc = false
|
10
10
|
s.authors = ["Jenna 'Bluebie' Fox"]
|
11
|
-
s.files = ["README.rdoc", "legs.gemspec", "lib/legs.rb", "examples/echo-server.rb", "examples/chat-server.rb", "examples/shoes-chat-client.rb", "test/
|
11
|
+
s.files = ["README.rdoc", "legs.gemspec", "lib/legs.rb", "examples/echo-server.rb", "examples/chat-server.rb", "examples/shoes-chat-client.rb", "test/test_legs.rb"]
|
12
12
|
s.add_dependency("json_pure", ["> 1.1.0"])
|
13
13
|
end
|
data/test/test_legs.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
# Makes use of ZenTest. Install the 'ZenTest' gem, then run this ruby script in a terminal to see the results!
|
2
|
+
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
|
3
|
+
require '../lib/legs'
|
4
|
+
|
5
|
+
# want to see errors, don't want to see excessively verbose logging normally
|
6
|
+
Thread.abort_on_exception = true
|
7
|
+
#Legs.log = true
|
8
|
+
|
9
|
+
# class to test the marshaling
|
10
|
+
class Marshal::TesterClass; attr_accessor :a, :b, :c; end
|
11
|
+
|
12
|
+
# a simple server to test with
|
13
|
+
Legs.start(6425) do
|
14
|
+
def echo(text)
|
15
|
+
return text
|
16
|
+
end
|
17
|
+
|
18
|
+
def count
|
19
|
+
caller.meta[:counter] ||= 0
|
20
|
+
caller.meta[:counter] += 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def methods
|
24
|
+
'overridden'
|
25
|
+
end
|
26
|
+
|
27
|
+
def error
|
28
|
+
raise "This is a fake error"
|
29
|
+
end
|
30
|
+
|
31
|
+
def notified
|
32
|
+
$notified = true
|
33
|
+
end
|
34
|
+
|
35
|
+
def marshal
|
36
|
+
obj = Marshal::TesterClass.new
|
37
|
+
obj.a = 1; obj.b = 2; obj.c = 3
|
38
|
+
return obj
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_connect
|
42
|
+
$server_instance = caller
|
43
|
+
end
|
44
|
+
|
45
|
+
def on_some_event
|
46
|
+
$some_event_ran = true
|
47
|
+
end
|
48
|
+
|
49
|
+
# tests that we can call stuff back over the caller's socket
|
50
|
+
def bidirectional; caller.notify!(:bidirectional_test_reciever); end
|
51
|
+
def bidirectional_test_reciever; $bidirectional_worked = true; end
|
52
|
+
end
|
53
|
+
|
54
|
+
Remote = Legs.new('localhost', 6425)
|
55
|
+
|
56
|
+
|
57
|
+
class TestLegsObject < Test::Unit::TestCase
|
58
|
+
def test_class_broadcast
|
59
|
+
$notified = false
|
60
|
+
Legs.broadcast(:notified)
|
61
|
+
sleep 0.5
|
62
|
+
assert_equal(true, $notified)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_class_connections
|
66
|
+
assert_equal(2, Legs.connections.length)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_class_event
|
70
|
+
Legs.event :some_event, nil
|
71
|
+
sleep 0.1
|
72
|
+
assert_equal(true, $some_event_ran)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_class_find_user_by_object_id
|
76
|
+
assert_equal(Legs.incoming.first, Legs.find_user_by_object_id(Legs.incoming.first.object_id))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_class_find_users_by_meta
|
80
|
+
Legs.incoming.first.meta[:id] = 'This is the incoming legs instance'
|
81
|
+
assert_equal(true, Legs.find_users_by_meta(:id => /incoming legs/).include?(Legs.incoming.first))
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_class_incoming
|
85
|
+
assert_equal(true, Legs.incoming.length > 0)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_class_outgoing
|
89
|
+
assert_equal(true, Legs.outgoing.is_a?(Array))
|
90
|
+
assert_equal(1, Legs.outgoing.length)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_class_open
|
94
|
+
instance = nil
|
95
|
+
Legs.open('localhost', 6425) do |i|
|
96
|
+
instance = i
|
97
|
+
end
|
98
|
+
assert_equal(Legs, instance.class)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_class_started_eh
|
102
|
+
assert_equal(true, Legs.started?)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_connected_eh
|
106
|
+
assert_equal(true, Remote.connected?)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_close_bang
|
110
|
+
ii = Legs.new('localhost', 6425)
|
111
|
+
assert_equal(2, Legs.outgoing.length)
|
112
|
+
ii.close!
|
113
|
+
assert_equal(1, Legs.outgoing.length)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_meta
|
117
|
+
assert_equal(true, Remote.meta.is_a?(Hash))
|
118
|
+
Remote.meta[:yada] = 'Yada'
|
119
|
+
assert_equal('Yada', Remote.meta[:yada])
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_notify_bang
|
123
|
+
$notified = false
|
124
|
+
Remote.notify! :notified
|
125
|
+
sleep(0.2)
|
126
|
+
assert_equal(true, $notified)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_parent
|
130
|
+
assert_equal(false, Remote.parent)
|
131
|
+
assert_equal(Legs, Legs.incoming.first.parent)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_send_bang
|
135
|
+
assert_equal(123, Remote.echo(123))
|
136
|
+
assert_equal(123, Remote.send!(:echo, 123))
|
137
|
+
|
138
|
+
# check async
|
139
|
+
abc = 0
|
140
|
+
Remote.echo(123) { |r| abc = r.value }
|
141
|
+
sleep 0.2
|
142
|
+
assert_equal(123, abc)
|
143
|
+
|
144
|
+
# check it catches ancestor method calls
|
145
|
+
assert_equal('overridden', Remote.methods)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_symbol_marshaling
|
149
|
+
assert_equal(Symbol, Remote.echo(:test).class)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_socket
|
153
|
+
assert_equal(true, Remote.socket.is_a?(BasicSocket))
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_marshaling
|
157
|
+
object = Remote.marshal
|
158
|
+
assert_equal(1, object.a)
|
159
|
+
assert_equal(2, object.b)
|
160
|
+
assert_equal(3, object.c)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_bidirectional
|
164
|
+
$bidirectional_worked = false; Remote.bidirectional; sleep 0.2
|
165
|
+
assert_equal(true, $bidirectional_worked)
|
166
|
+
end
|
167
|
+
|
168
|
+
# makes sure the define_method thingo works for adding blocks to Legs
|
169
|
+
def test_adding_block
|
170
|
+
bound_var = 'Ladedadedah'
|
171
|
+
Legs.define_method(:defined_meth) { bound_var }
|
172
|
+
assert_equal(bound_var, Remote.defined_meth)
|
173
|
+
end
|
174
|
+
|
175
|
+
# this is to make sure we can run the start method a ton of times without bad side effects
|
176
|
+
def test_start_again_and_again
|
177
|
+
Legs.start
|
178
|
+
Legs.start { def adding_another_method; true; end }
|
179
|
+
assert_equal(true, Remote.adding_another_method)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
module TestLegs
|
184
|
+
class TestResult < Test::Unit::TestCase
|
185
|
+
def test_data
|
186
|
+
result = nil
|
187
|
+
Remote.echo(123) { |r| result = r }
|
188
|
+
sleep(0.2)
|
189
|
+
|
190
|
+
assert_equal(123, result.data['result'])
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_result
|
194
|
+
normal_result = Legs::Result.new({'id'=>1, 'result' => 'Hello World'})
|
195
|
+
error_result = Legs::Result.new({'id'=>2, 'error' => 'Uh oh Spagetti-o\'s'})
|
196
|
+
|
197
|
+
assert_equal(normal_result.value, 'Hello World')
|
198
|
+
assert_equal(normal_result.result, 'Hello World')
|
199
|
+
assert_equal((error_result.value rescue :good), :good)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Bluebie-legs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jenna 'Bluebie' Fox
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,7 +36,7 @@ files:
|
|
36
36
|
- examples/echo-server.rb
|
37
37
|
- examples/chat-server.rb
|
38
38
|
- examples/shoes-chat-client.rb
|
39
|
-
- test/
|
39
|
+
- test/test_legs.rb
|
40
40
|
has_rdoc: false
|
41
41
|
homepage: http://github.com/Bluebie/legs
|
42
42
|
post_install_message:
|