woyo-world 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,52 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'woyo/world/character'
|
2
3
|
require 'woyo/world/world'
|
3
4
|
require 'woyo/world/location'
|
4
5
|
|
5
6
|
describe Woyo::Character do
|
6
|
-
|
7
|
+
|
8
|
+
let(:char) { Woyo::Character.new :boss }
|
9
|
+
|
7
10
|
it 'has attributes' do
|
8
|
-
|
9
|
-
|
11
|
+
expect(char.attributes).to be_instance_of Woyo::Attributes::AttributesHash
|
12
|
+
expect(char.attributes.names.sort).to eq [:description,:name]
|
10
13
|
end
|
11
14
|
|
12
15
|
it 'name attribute defaults to id' do
|
13
|
-
|
14
|
-
wo.name.should eq 'Boss'
|
16
|
+
expect(char.name).to eq 'Boss'
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'accepts world for parameter context:' do
|
18
20
|
wo = nil
|
19
21
|
expect { wo = Woyo::Character.new(:my_id, context: Woyo::World.new) }.to_not raise_error
|
20
|
-
wo.context.
|
22
|
+
expect(wo.context).to be_instance_of Woyo::World
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'accepts location for parameter context:' do
|
24
26
|
wo = nil
|
25
27
|
expect { wo = Woyo::Character.new(:my_id, context: Woyo::Location.new(:here)) }.to_not raise_error
|
26
|
-
wo.context.
|
27
|
-
wo.context.id.
|
28
|
+
expect(wo.context).to be_instance_of Woyo::Location
|
29
|
+
expect(wo.context.id).to eq :here
|
28
30
|
end
|
29
31
|
|
30
|
-
it 'can go way' do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
32
|
+
# it 'can go way' do
|
33
|
+
# world = Woyo::World.new do
|
34
|
+
# location :home do
|
35
|
+
# way :out do
|
36
|
+
# to :away
|
37
|
+
# end
|
38
|
+
# character :tom
|
39
|
+
# end
|
40
|
+
# location :away do
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# home = world.locations[:home]
|
44
|
+
# away = world.locations[:away]
|
45
|
+
# tom = home.characters[:tom]
|
46
|
+
# tom.location.should be home
|
47
|
+
# tom.go :out
|
48
|
+
# tom.location.should be away
|
49
|
+
# home.characters[:tom].should be_nil
|
50
|
+
# away.characters[:tom].should eq tom
|
51
|
+
# end
|
50
52
|
|
51
53
|
end
|
52
54
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'woyo/world/evaluate'
|
3
|
+
|
4
|
+
describe Woyo::Evaluate do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class EvalTest
|
8
|
+
include Woyo::Evaluate
|
9
|
+
children :dog, :cat
|
10
|
+
end
|
11
|
+
class Dog ; def initialize id, context: nil ; end ; end
|
12
|
+
class Cat ; def initialize id, context: nil ; end ; end
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#evaluate' do
|
16
|
+
|
17
|
+
it 'instance evals block with arity 0' do
|
18
|
+
evt = EvalTest.new
|
19
|
+
result = evt.evaluate { self.should == evt }
|
20
|
+
expect(result).to be evt
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'passes self to block with arity 1' do
|
24
|
+
evt = EvalTest.new
|
25
|
+
result = evt.evaluate { |scope| expect(scope).to be evt }
|
26
|
+
expect(result).to be evt
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can list classes to contain' do
|
32
|
+
expect(EvalTest.children).to eq [ :dog, :cat ]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can add classes to contain' do
|
36
|
+
class EvalTest
|
37
|
+
children :cow
|
38
|
+
children :duck
|
39
|
+
end
|
40
|
+
# class Cow ; def initialize id, context: nil ; end ; end
|
41
|
+
# class Duck ; def initialize id, context: nil ; end ; end
|
42
|
+
expect(EvalTest.children).to eq [ :dog, :cat, :cow, :duck ]
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'can create child objects' do
|
46
|
+
evt = EvalTest.new
|
47
|
+
dog = evt.dog :brown
|
48
|
+
expect(dog).to be_instance_of Dog
|
49
|
+
expect(evt.dog(:brown)).to be dog
|
50
|
+
expect(evt.dogs[:brown]).to be dog
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'has hashes of each class of child objects' do
|
54
|
+
evt = EvalTest.new
|
55
|
+
dog_brown = evt.dog :brown
|
56
|
+
dog_black = evt.dog :black
|
57
|
+
cat_white = evt.cat :white
|
58
|
+
cat_black = evt.cat :black
|
59
|
+
expect(evt.dogs).to eq Hash[ brown: dog_brown, black: dog_black ]
|
60
|
+
expect(evt.cats).to eq Hash[ white: cat_white, black: cat_black ]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'hash a hash of all classes of child objects' do
|
64
|
+
evt = EvalTest.new
|
65
|
+
dog_brown = evt.dog :brown
|
66
|
+
dog_black = evt.dog :black
|
67
|
+
cat_white = evt.cat :white
|
68
|
+
cat_black = evt.cat :black
|
69
|
+
expect(evt.children.keys).to eq [ :dog, :cat ]
|
70
|
+
cats = Hash[ white: cat_white, black: cat_black ]
|
71
|
+
dogs = Hash[ brown: dog_brown, black: dog_black ]
|
72
|
+
expect(evt.children).to eq Hash[ dog: dogs, cat: cats ]
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'woyo/world/group'
|
2
3
|
|
3
4
|
describe Woyo::Attributes::AttributesHash do
|
@@ -19,14 +20,14 @@ describe Woyo::Attributes::AttributesHash do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'is a kind of hash' do
|
22
|
-
@attributes.
|
23
|
-
@attributes[:test].
|
23
|
+
expect(@attributes).to be_kind_of Hash
|
24
|
+
expect(@attributes[:test]).to be nil
|
24
25
|
@attributes[:test] = true
|
25
|
-
@attributes[:test].
|
26
|
+
expect(@attributes[:test]).to be true
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'provides list of attribute names' do
|
29
|
-
@attributes.names.
|
30
|
+
expect(@attributes.names).to eq [:test]
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'registers attribute listeners' do
|
@@ -34,27 +35,27 @@ describe Woyo::Attributes::AttributesHash do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'maintains list of attribute listeners' do
|
37
|
-
@attributes.listeners.
|
38
|
-
@attributes.listeners[:test].
|
38
|
+
expect(@attributes.listeners).to be_kind_of Hash
|
39
|
+
expect(@attributes.listeners[:test]).to be @listener
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'notifies listeners of attribute change' do
|
42
|
-
@listener.notified.
|
43
|
-
@listener.attr.
|
44
|
-
@listener.value.
|
43
|
+
expect(@listener.notified).to be false
|
44
|
+
expect(@listener.attr).to be nil
|
45
|
+
expect(@listener.value).to be nil
|
45
46
|
@attributes[:test] = :new_value
|
46
|
-
@listener.notified.
|
47
|
-
@listener.attr.
|
48
|
-
@listener.value.
|
47
|
+
expect(@listener.notified).to eq true
|
48
|
+
expect(@listener.attr).to eq :test
|
49
|
+
expect(@listener.value).to eq :new_value
|
49
50
|
end
|
50
51
|
|
51
52
|
it 'does not notify listener if attribute does not change' do
|
52
53
|
@attributes[:test] = :same_value
|
53
54
|
@listener = Listener.new
|
54
55
|
@attributes.add_attribute_listener :test, @listener
|
55
|
-
@listener.notified.
|
56
|
+
expect(@listener.notified).to be false
|
56
57
|
@attributes[:test] = :same_value
|
57
|
-
@listener.notified.
|
58
|
+
expect(@listener.notified).to be false
|
58
59
|
end
|
59
60
|
|
60
61
|
end
|
@@ -72,74 +73,74 @@ describe Woyo::Attributes::Group do
|
|
72
73
|
end
|
73
74
|
|
74
75
|
it 'maintains list of members' do
|
75
|
-
@group.members.
|
76
|
+
expect(@group.members).to eq [ :larry, :curly, :moe ]
|
76
77
|
end
|
77
78
|
|
78
79
|
it 'member names can be listed' do
|
79
|
-
@group.names.
|
80
|
+
expect(@group.names).to eq [ :larry, :curly, :moe ]
|
80
81
|
end
|
81
82
|
|
82
83
|
it 'members are backed by attributes' do
|
83
84
|
@group[:larry] = 'dumb'
|
84
85
|
@group[:curly] = 'bald'
|
85
86
|
@group[:moe] = 'smart'
|
86
|
-
@group[:larry].
|
87
|
-
@group[:curly].
|
88
|
-
@group[:moe].
|
89
|
-
@attributes[:larry].
|
90
|
-
@attributes[:curly].
|
91
|
-
@attributes[:moe].
|
87
|
+
expect(@group[:larry]).to eq 'dumb'
|
88
|
+
expect(@group[:curly]).to eq 'bald'
|
89
|
+
expect(@group[:moe]).to eq 'smart'
|
90
|
+
expect(@attributes[:larry]).to eq 'dumb'
|
91
|
+
expect(@attributes[:curly]).to eq 'bald'
|
92
|
+
expect(@attributes[:moe]).to eq 'smart'
|
92
93
|
end
|
93
94
|
|
94
95
|
it 'member values can be listed' do
|
95
|
-
@group.values.
|
96
|
+
expect(@group.values).to eq %w( dumb bald smart )
|
96
97
|
end
|
97
98
|
|
98
99
|
end
|
99
100
|
|
100
|
-
describe Woyo::Attributes::
|
101
|
+
describe Woyo::Attributes::Exclusion do
|
101
102
|
|
102
103
|
before :all do
|
103
|
-
@group = Woyo::Attributes::
|
104
|
+
@group = Woyo::Attributes::Exclusion.new Woyo::Attributes::AttributesHash.new, :warm, :cool, :cold
|
104
105
|
end
|
105
106
|
|
106
107
|
it 'has default' do
|
107
|
-
@group.default.
|
108
|
+
expect(@group.default).to eq :warm
|
108
109
|
end
|
109
110
|
|
110
111
|
it 'defaults to first member true, the rest false' do
|
111
|
-
@group[:warm].
|
112
|
-
@group[:cool].
|
113
|
-
@group[:cold].
|
112
|
+
expect(@group[:warm]).to be true
|
113
|
+
expect(@group[:cool]).to be false
|
114
|
+
expect(@group[:cold]).to be false
|
114
115
|
end
|
115
116
|
|
116
117
|
it 'registers as listener for attributes' do
|
117
118
|
@group.members.each do |member|
|
118
|
-
@group.attributes.listeners[member].
|
119
|
+
expect(@group.attributes.listeners[member]).to be @group
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
123
|
it 'setting a member true changes the rest to false' do
|
123
124
|
@group[:cold] = true
|
124
|
-
@group[:warm].
|
125
|
-
@group[:cool].
|
126
|
-
@group[:cold].
|
125
|
+
expect(@group[:warm]).to be false
|
126
|
+
expect(@group[:cool]).to be false
|
127
|
+
expect(@group[:cold]).to be true
|
127
128
|
end
|
128
129
|
|
129
130
|
it 'for a group > 2 members setting a true member false reverts to default' do
|
130
131
|
@group[:cold] = false
|
131
|
-
@group[:warm].
|
132
|
-
@group[:cool].
|
133
|
-
@group[:cold].
|
132
|
+
expect(@group[:warm]).to be true
|
133
|
+
expect(@group[:cool]).to be false
|
134
|
+
expect(@group[:cold]).to be false
|
134
135
|
end
|
135
136
|
|
136
137
|
it 'for a binary group setting a true member false sets the other true' do
|
137
|
-
@binary_group = Woyo::Attributes::
|
138
|
-
@binary_group[:yes].
|
139
|
-
@binary_group[:no].
|
138
|
+
@binary_group = Woyo::Attributes::Exclusion.new Woyo::Attributes::AttributesHash.new, :yes, :no
|
139
|
+
expect(@binary_group[:yes]).to be true
|
140
|
+
expect(@binary_group[:no]).to be false
|
140
141
|
@binary_group[:yes] = false
|
141
|
-
@binary_group[:yes].
|
142
|
-
@binary_group[:no].
|
142
|
+
expect(@binary_group[:yes]).to be false
|
143
|
+
expect(@binary_group[:no]).to be true
|
143
144
|
end
|
144
145
|
|
145
146
|
it 'can only set existing members' do
|
@@ -149,14 +150,14 @@ describe Woyo::Attributes::BooleanGroup do
|
|
149
150
|
it 'can be reset to default!' do
|
150
151
|
@group[:cool] = true
|
151
152
|
@group.default!
|
152
|
-
@group[:warm].
|
153
|
+
expect(@group[:warm]).to eq true
|
153
154
|
end
|
154
155
|
|
155
156
|
it '#value returns name of true member' do
|
156
157
|
@group[:warm] = true
|
157
|
-
@group.value.
|
158
|
+
expect(@group.value).to eq :warm
|
158
159
|
@group[:cold] = true
|
159
|
-
@group.value.
|
160
|
+
expect(@group.value).to eq :cold
|
160
161
|
end
|
161
162
|
|
162
163
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'woyo/world/world'
|
3
|
+
require 'woyo/world/item'
|
4
|
+
|
5
|
+
describe Woyo::Item do
|
6
|
+
|
7
|
+
context 'in world' do
|
8
|
+
|
9
|
+
let(:item) { Woyo::Item.new :thing, context: Woyo::World.new }
|
10
|
+
|
11
|
+
it 'accepts world for parameter context' do
|
12
|
+
expect(item.context).to be_instance_of Woyo::World
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#world' do
|
16
|
+
expect(item.world).to be_instance_of Woyo::World
|
17
|
+
end
|
18
|
+
|
19
|
+
it '#location' do
|
20
|
+
expect(item.location).to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'in a location' do
|
26
|
+
|
27
|
+
let(:item) { Woyo::Item.new :thing, context: Woyo::Location.new(:here, context: Woyo::World.new) }
|
28
|
+
|
29
|
+
it 'accepts location for parameter context:' do
|
30
|
+
expect(item.context).to be_instance_of Woyo::Location
|
31
|
+
expect(item.context.id).to eq :here
|
32
|
+
end
|
33
|
+
|
34
|
+
it '#location' do
|
35
|
+
expect(item.location).to be_instance_of Woyo::Location
|
36
|
+
expect(item.location.id).to eq :here
|
37
|
+
end
|
38
|
+
|
39
|
+
it '#world' do
|
40
|
+
expect(item.world).to be_instance_of Woyo::World
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -1,23 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'woyo/world/world'
|
2
3
|
require 'woyo/world/location'
|
4
|
+
require 'woyo/world/item'
|
3
5
|
require 'woyo/world/way'
|
4
6
|
|
5
7
|
describe Woyo::Location do
|
6
8
|
|
7
|
-
|
8
|
-
expected_attrs = [:name,:description]
|
9
|
-
Woyo::Location.attributes.sort.should eq expected_attrs.sort
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'name attribute defaults to id' do
|
13
|
-
wo = Woyo::Location.new(:home)
|
14
|
-
wo.name.should eq 'Home'
|
15
|
-
end
|
9
|
+
let(:location) { Woyo::Location.new :home }
|
16
10
|
|
17
11
|
it 'accepts world for parameter context:' do
|
18
12
|
wo = nil
|
19
13
|
expect { wo = Woyo::Location.new(:my_id, context: Woyo::World.new) }.to_not raise_error
|
20
|
-
wo.context.
|
14
|
+
expect(wo.context).to be_instance_of Woyo::World
|
15
|
+
end
|
16
|
+
|
17
|
+
it '#here' do
|
18
|
+
home = Woyo::Location.new :home
|
19
|
+
expect(home.here).to be home
|
20
|
+
end
|
21
|
+
|
22
|
+
it '#world' do
|
23
|
+
world = Woyo::World.new
|
24
|
+
home = Woyo::Location.new :home, context: world
|
25
|
+
expect(home.world).to eq world
|
21
26
|
end
|
22
27
|
|
23
28
|
context 'ways' do
|
@@ -28,8 +33,8 @@ describe Woyo::Location do
|
|
28
33
|
way( :down ) { to :cellar }
|
29
34
|
way( :out ) { to :garden }
|
30
35
|
end
|
31
|
-
home.ways.count.
|
32
|
-
home.ways.keys.
|
36
|
+
expect(home.ways.count).to eq 3
|
37
|
+
expect(home.ways.keys).to eq [ :up, :down, :out ]
|
33
38
|
end
|
34
39
|
|
35
40
|
it 'are from here' do
|
@@ -39,7 +44,7 @@ describe Woyo::Location do
|
|
39
44
|
end
|
40
45
|
end
|
41
46
|
door = home.ways[:door]
|
42
|
-
door.from.
|
47
|
+
expect(door.from).to eq home
|
43
48
|
end
|
44
49
|
|
45
50
|
it 'go to locations' do
|
@@ -49,32 +54,43 @@ describe Woyo::Location do
|
|
49
54
|
end
|
50
55
|
end
|
51
56
|
door = home.ways[:door]
|
52
|
-
door.to.
|
53
|
-
door.to.id.
|
57
|
+
expect(door.to).to be_instance_of Woyo::Location
|
58
|
+
expect(door.to.id).to eq :away
|
54
59
|
end
|
55
60
|
|
56
61
|
end
|
57
62
|
|
58
|
-
|
59
|
-
home = Woyo::Location.new :home
|
60
|
-
home.here.should be home
|
61
|
-
end
|
63
|
+
context 'items' do
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
it '#characters' do
|
70
|
-
home = Woyo::Location.new :home do
|
71
|
-
character :peter do
|
65
|
+
let( :home ) do
|
66
|
+
home = Woyo::Location.new :home do
|
67
|
+
item( :thing1 ) { description 'Thing One' }
|
68
|
+
item( :thing2 ) { description 'Thing two' }
|
72
69
|
end
|
73
70
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
|
72
|
+
it 'are listed' do
|
73
|
+
expect(home.items.count).to eq 2
|
74
|
+
expect(home.items.keys).to eq [ :thing1, :thing2 ]
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'are accessible' do
|
78
|
+
expect(thing = home.items[:thing1]).to be_instance_of Woyo::Item
|
79
|
+
expect(thing.id).to eq :thing1
|
80
|
+
expect(thing.description).to eq 'Thing One'
|
81
|
+
end
|
82
|
+
|
78
83
|
end
|
79
84
|
|
85
|
+
# it '#characters' do
|
86
|
+
# home = Woyo::Location.new :home do
|
87
|
+
# character :peter do
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# home.characters.size.should eq 1
|
91
|
+
# peter = home.characters[:peter]
|
92
|
+
# peter.should be_instance_of Woyo::Character
|
93
|
+
# peter.location.should be home
|
94
|
+
# end
|
95
|
+
|
80
96
|
end
|