woyo-world 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/lib/woyo/world/actions.rb +24 -0
- data/lib/woyo/world/attributes.rb +105 -154
- data/lib/woyo/world/character.rb +4 -1
- data/lib/woyo/world/{dsl.rb → evaluate.rb} +1 -2
- data/lib/woyo/world/group.rb +21 -6
- data/lib/woyo/world/item.rb +26 -0
- data/lib/woyo/world/location.rb +5 -3
- data/lib/woyo/world/version.rb +1 -1
- data/lib/woyo/world/way.rb +5 -4
- data/lib/woyo/world/world.rb +7 -3
- data/lib/woyo/world/world_object.rb +8 -4
- data/rspec.json +1 -0
- data/spec/spec_doc.haml +68 -0
- data/spec/spec_doc_formatter.rb +89 -0
- data/spec/spec_helper.rb +115 -0
- data/spec/woyo/dsl/dsl_spec.rb +367 -0
- data/spec/woyo/world/actions_spec.rb +71 -0
- data/spec/woyo/world/attributes_spec.rb +300 -382
- data/spec/woyo/world/character_spec.rb +30 -28
- data/spec/woyo/world/evaluate_spec.rb +75 -0
- data/spec/woyo/world/group_spec.rb +45 -44
- data/spec/woyo/world/item_spec.rb +46 -0
- data/spec/woyo/world/location_spec.rb +48 -32
- data/spec/woyo/world/way_spec.rb +54 -45
- data/spec/woyo/world/world_object_spec.rb +48 -6
- data/spec/woyo/world/world_spec.rb +15 -7
- data/todo.txt +2 -2
- data/woyo-world.gemspec +3 -2
- metadata +38 -11
- data/spec/woyo/world/dsl_spec.rb +0 -74
- data/spec/woyo/world/language_spec.rb +0 -350
data/spec/woyo/world/dsl_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'woyo/world/dsl'
|
2
|
-
|
3
|
-
describe Woyo::DSL do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
class DSLTest
|
7
|
-
include Woyo::DSL
|
8
|
-
children :dog, :cat
|
9
|
-
end
|
10
|
-
class Dog ; def initialize id, context: nil ; end ; end
|
11
|
-
class Cat ; def initialize id, context: nil ; end ; end
|
12
|
-
end
|
13
|
-
|
14
|
-
context '#evaluate' do
|
15
|
-
|
16
|
-
it 'instance evals block with arity 0' do
|
17
|
-
dsl = DSLTest.new
|
18
|
-
result = dsl.evaluate { self.should == dsl }
|
19
|
-
result.should be dsl
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'passes self to block with arity 1' do
|
23
|
-
dsl = DSLTest.new
|
24
|
-
result = dsl.evaluate { |scope| scope.should be dsl }
|
25
|
-
result.should be dsl
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'can list classes to contain' do
|
31
|
-
DSLTest.children.should eq [ :dog, :cat ]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'can add classes to contain' do
|
35
|
-
class DSLTest
|
36
|
-
children :cow
|
37
|
-
children :duck
|
38
|
-
end
|
39
|
-
# class Cow ; def initialize id, context: nil ; end ; end
|
40
|
-
# class Duck ; def initialize id, context: nil ; end ; end
|
41
|
-
DSLTest.children.should eq [ :dog, :cat, :cow, :duck ]
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'can create child objects' do
|
45
|
-
dsl = DSLTest.new
|
46
|
-
dog = dsl.dog :brown
|
47
|
-
dog.should be_instance_of Dog
|
48
|
-
dsl.dog(:brown).should be dog
|
49
|
-
dsl.dogs[:brown].should be dog
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'has hashes of each class of child objects' do
|
53
|
-
dsl = DSLTest.new
|
54
|
-
dog_brown = dsl.dog :brown
|
55
|
-
dog_black = dsl.dog :black
|
56
|
-
cat_white = dsl.cat :white
|
57
|
-
cat_black = dsl.cat :black
|
58
|
-
dsl.dogs.should eq Hash[ brown: dog_brown, black: dog_black ]
|
59
|
-
dsl.cats.should eq Hash[ white: cat_white, black: cat_black ]
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'hash a hash of all classes of child objects' do
|
63
|
-
dsl = DSLTest.new
|
64
|
-
dog_brown = dsl.dog :brown
|
65
|
-
dog_black = dsl.dog :black
|
66
|
-
cat_white = dsl.cat :white
|
67
|
-
cat_black = dsl.cat :black
|
68
|
-
dsl.children.keys.should eq [ :dog, :cat ]
|
69
|
-
cats = Hash[ white: cat_white, black: cat_black ]
|
70
|
-
dogs = Hash[ brown: dog_brown, black: dog_black ]
|
71
|
-
dsl.children.should eq Hash[ dog: dogs, cat: cats ]
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,350 +0,0 @@
|
|
1
|
-
require 'woyo/world/world'
|
2
|
-
|
3
|
-
describe 'DSL' do
|
4
|
-
|
5
|
-
context 'world' do
|
6
|
-
|
7
|
-
context 'location' do
|
8
|
-
|
9
|
-
it 'new without block' do
|
10
|
-
world = Woyo::World.new do
|
11
|
-
location :home
|
12
|
-
location :away
|
13
|
-
location :lost
|
14
|
-
end
|
15
|
-
world.should be_instance_of Woyo::World
|
16
|
-
world.locations.count.should eq 3
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'new with empty block' do
|
20
|
-
world = Woyo::World.new do
|
21
|
-
location :home do ; end
|
22
|
-
location :away do ; end
|
23
|
-
location :lost do ; end
|
24
|
-
end
|
25
|
-
world.should be_instance_of Woyo::World
|
26
|
-
world.locations.count.should eq 3
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'new with attributes' do
|
30
|
-
world = Woyo::World.new do
|
31
|
-
location :home do
|
32
|
-
name 'Home'
|
33
|
-
description 'Sweet'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
world.should be_instance_of Woyo::World
|
37
|
-
world.locations.count.should eq 1
|
38
|
-
home = world.locations[:home]
|
39
|
-
home.id.should eq :home
|
40
|
-
home.name.should eq 'Home'
|
41
|
-
home.description.should eq 'Sweet'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'existing with attributes' do
|
45
|
-
world = Woyo::World.new do
|
46
|
-
location :home do
|
47
|
-
name 'Home'
|
48
|
-
description 'Okay'
|
49
|
-
end
|
50
|
-
location :home do
|
51
|
-
description 'Sweet'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
world.should be_instance_of Woyo::World
|
55
|
-
world.locations.count.should eq 1
|
56
|
-
home = world.locations[:home]
|
57
|
-
home.id.should eq :home
|
58
|
-
home.name.should eq 'Home'
|
59
|
-
home.description.should eq 'Sweet'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'multiple with attributes' do
|
63
|
-
world = Woyo::World.new do
|
64
|
-
location :home do
|
65
|
-
name 'Home'
|
66
|
-
description 'Sweet'
|
67
|
-
end
|
68
|
-
location :away do
|
69
|
-
name 'Away'
|
70
|
-
description 'Okay'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
world.should be_instance_of Woyo::World
|
74
|
-
world.locations.count.should eq 2
|
75
|
-
home = world.locations[:home]
|
76
|
-
home.id.should eq :home
|
77
|
-
home.name.should eq 'Home'
|
78
|
-
home.description.should eq 'Sweet'
|
79
|
-
away = world.locations[:away]
|
80
|
-
away.id.should eq :away
|
81
|
-
away.name.should eq 'Away'
|
82
|
-
away.description.should eq 'Okay'
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'ways' do
|
86
|
-
|
87
|
-
context 'new way' do
|
88
|
-
|
89
|
-
it 'to new location' do
|
90
|
-
world = Woyo::World.new do
|
91
|
-
location :home do
|
92
|
-
way :door do
|
93
|
-
name 'Large Wooden Door'
|
94
|
-
to :away
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
home = world.locations[:home]
|
99
|
-
home.ways.count.should eq 1
|
100
|
-
door = home.ways[:door]
|
101
|
-
door.should be_instance_of Woyo::Way
|
102
|
-
door.name.should eq 'Large Wooden Door'
|
103
|
-
door.to.should be_instance_of Woyo::Location
|
104
|
-
door.to.id.should eq :away
|
105
|
-
away = world.locations[:away]
|
106
|
-
away.ways.count.should eq 0
|
107
|
-
door.to.should eq away
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'to existing location' do
|
111
|
-
world = Woyo::World.new do
|
112
|
-
location :away do
|
113
|
-
end
|
114
|
-
location :home do
|
115
|
-
way :door do
|
116
|
-
name 'Large Wooden Door'
|
117
|
-
to :away
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
home = world.locations[:home]
|
122
|
-
home.ways.count.should eq 1
|
123
|
-
door = home.ways[:door]
|
124
|
-
door.should be_instance_of Woyo::Way
|
125
|
-
door.name.should eq 'Large Wooden Door'
|
126
|
-
door.to.should be_instance_of Woyo::Location
|
127
|
-
door.to.id.should eq :away
|
128
|
-
away = world.locations[:away]
|
129
|
-
away.ways.count.should eq 0
|
130
|
-
door.to.should eq away
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'to same location' do
|
134
|
-
world = Woyo::World.new do
|
135
|
-
location :home do
|
136
|
-
way :door do
|
137
|
-
name 'Large Wooden Door'
|
138
|
-
to :home
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
home = world.locations[:home]
|
143
|
-
home.ways.count.should eq 1
|
144
|
-
door = home.ways[:door]
|
145
|
-
door.should be_instance_of Woyo::Way
|
146
|
-
door.name.should eq 'Large Wooden Door'
|
147
|
-
door.to.should be_instance_of Woyo::Location
|
148
|
-
door.to.id.should eq :home
|
149
|
-
door.to.should eq home
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'existing way' do
|
155
|
-
|
156
|
-
it 'to new location' do
|
157
|
-
world = Woyo::World.new do
|
158
|
-
location :home do
|
159
|
-
way :door do
|
160
|
-
name 'Large Wooden Door'
|
161
|
-
description "Big, real big!"
|
162
|
-
end
|
163
|
-
way :door do
|
164
|
-
description 'Nicer'
|
165
|
-
to :away
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
home = world.locations[:home]
|
170
|
-
home.ways.count.should eq 1
|
171
|
-
door = home.ways[:door]
|
172
|
-
door.name.should eq 'Large Wooden Door'
|
173
|
-
door.description.should eq "Nicer"
|
174
|
-
door.to.should be_instance_of Woyo::Location
|
175
|
-
door.to.id.should eq :away
|
176
|
-
away = world.locations[:away]
|
177
|
-
away.ways.count.should eq 0
|
178
|
-
door.to.should eq away
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'to existing location' do
|
182
|
-
world = Woyo::World.new do
|
183
|
-
location :away do
|
184
|
-
end
|
185
|
-
location :home do
|
186
|
-
way :door do
|
187
|
-
name 'Large Wooden Door'
|
188
|
-
description "Big, real big!"
|
189
|
-
end
|
190
|
-
way :door do
|
191
|
-
description 'Nicer'
|
192
|
-
to :away
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
home = world.locations[:home]
|
197
|
-
home.ways.count.should eq 1
|
198
|
-
door = home.ways[:door]
|
199
|
-
door.name.should eq 'Large Wooden Door'
|
200
|
-
door.description.should eq "Nicer"
|
201
|
-
door.to.should be_instance_of Woyo::Location
|
202
|
-
door.to.id.should eq :away
|
203
|
-
away = world.locations[:away]
|
204
|
-
away.ways.count.should eq 0
|
205
|
-
door.to.should eq away
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'to same location' do
|
209
|
-
world = Woyo::World.new do
|
210
|
-
location :home do
|
211
|
-
way :door do
|
212
|
-
name 'Large Wooden Door'
|
213
|
-
description "Big, real big!"
|
214
|
-
end
|
215
|
-
way :door do
|
216
|
-
description 'Nicer'
|
217
|
-
to :home
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
home = world.locations[:home]
|
222
|
-
home.ways.count.should eq 1
|
223
|
-
door = home.ways[:door]
|
224
|
-
door.name.should eq 'Large Wooden Door'
|
225
|
-
door.description.should eq "Nicer"
|
226
|
-
door.to.should be_instance_of Woyo::Location
|
227
|
-
door.to.id.should eq :home
|
228
|
-
door.to.should eq home
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'going' do
|
234
|
-
|
235
|
-
before :all do
|
236
|
-
@world = Woyo::World.new do
|
237
|
-
location :room do
|
238
|
-
way :stairs do
|
239
|
-
to :cellar
|
240
|
-
description open: 'Rickety stairs lead down into darkness.',
|
241
|
-
closed: 'Broken stairs end in darkness.'
|
242
|
-
going open: 'Creaky steps lead uncertainly downwards...',
|
243
|
-
closed: 'The dangerous stairs are impassable.'
|
244
|
-
end
|
245
|
-
end
|
246
|
-
location :cellar do
|
247
|
-
description 'Dark and damp, as expected.'
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'an open way' do
|
253
|
-
room = @world.locations[:room]
|
254
|
-
stairs = room.ways[:stairs]
|
255
|
-
stairs.to.id.should eq :cellar
|
256
|
-
stairs.should be_open
|
257
|
-
stairs.description.should eq 'Rickety stairs lead down into darkness.'
|
258
|
-
stairs.go.should eq ( { go: true, going: 'Creaky steps lead uncertainly downwards...' } )
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'a closed way' do
|
262
|
-
room = @world.locations[:room]
|
263
|
-
stairs = room.ways[:stairs]
|
264
|
-
stairs.to.id.should eq :cellar
|
265
|
-
stairs.close!
|
266
|
-
stairs.should be_closed
|
267
|
-
stairs.description.should eq 'Broken stairs end in darkness.'
|
268
|
-
stairs.go.should eq ( { go: false, going: 'The dangerous stairs are impassable.' } )
|
269
|
-
end
|
270
|
-
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'new character' do
|
276
|
-
world = Woyo::World.new do
|
277
|
-
location :home do
|
278
|
-
character :jim do
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
home = world.locations[:home]
|
283
|
-
home.characters.count.should eq 1
|
284
|
-
jim = home.characters[:jim]
|
285
|
-
jim.location.should be home
|
286
|
-
end
|
287
|
-
|
288
|
-
it 'existing character' do
|
289
|
-
world = Woyo::World.new do
|
290
|
-
location :home do
|
291
|
-
character :jim do
|
292
|
-
name 'James'
|
293
|
-
description 'Jolly'
|
294
|
-
end
|
295
|
-
character :jim do
|
296
|
-
description 'Jovial'
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
home = world.locations[:home]
|
301
|
-
home.characters.count.should eq 1
|
302
|
-
jim = home.characters[:jim]
|
303
|
-
jim.location.should be home
|
304
|
-
jim.name.should eq 'James'
|
305
|
-
jim.description.should eq 'Jovial'
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'character' do
|
311
|
-
|
312
|
-
it 'new' do
|
313
|
-
world = Woyo::World.new do
|
314
|
-
character :jim do
|
315
|
-
name 'James'
|
316
|
-
description 'Jolly'
|
317
|
-
end
|
318
|
-
end
|
319
|
-
world.characters.count.should eq 1
|
320
|
-
world.characters[:jim].should be_instance_of Woyo::Character
|
321
|
-
jim = world.characters[:jim]
|
322
|
-
jim.location.should be_nil
|
323
|
-
jim.name.should eq 'James'
|
324
|
-
jim.description.should eq 'Jolly'
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'existing' do
|
328
|
-
world = Woyo::World.new do
|
329
|
-
character :jim do
|
330
|
-
name 'James'
|
331
|
-
description 'Jolly'
|
332
|
-
end
|
333
|
-
character :jim do
|
334
|
-
description 'Jovial'
|
335
|
-
end
|
336
|
-
end
|
337
|
-
world.characters.count.should eq 1
|
338
|
-
world.characters[:jim].should be_instance_of Woyo::Character
|
339
|
-
jim = world.characters[:jim]
|
340
|
-
jim.location.should be_nil
|
341
|
-
jim.name.should eq 'James'
|
342
|
-
jim.description.should eq 'Jovial'
|
343
|
-
end
|
344
|
-
|
345
|
-
end
|
346
|
-
|
347
|
-
end
|
348
|
-
|
349
|
-
end
|
350
|
-
|