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.
@@ -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
- expected_attrs = [:name,:description]
9
- Woyo::Character.attributes.sort.should eq expected_attrs.sort
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
- wo = Woyo::Character.new(:boss)
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.should be_instance_of Woyo::World
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.should be_instance_of Woyo::Location
27
- wo.context.id.should eq :here
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
- world = Woyo::World.new do
32
- location :home do
33
- way :out do
34
- to :away
35
- end
36
- character :tom
37
- end
38
- location :away do
39
- end
40
- end
41
- home = world.locations[:home]
42
- away = world.locations[:away]
43
- tom = home.characters[:tom]
44
- tom.location.should be home
45
- tom.go :out
46
- tom.location.should be away
47
- home.characters[:tom].should be_nil
48
- away.characters[:tom].should eq tom
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.should be_kind_of Hash
23
- @attributes[:test].should be nil
23
+ expect(@attributes).to be_kind_of Hash
24
+ expect(@attributes[:test]).to be nil
24
25
  @attributes[:test] = true
25
- @attributes[:test].should be true
26
+ expect(@attributes[:test]).to be true
26
27
  end
27
28
 
28
29
  it 'provides list of attribute names' do
29
- @attributes.names.should eq [:test]
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.should be_kind_of Hash
38
- @attributes.listeners[:test].should be @listener
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.should be false
43
- @listener.attr.should be nil
44
- @listener.value.should be nil
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.should eq true
47
- @listener.attr.should eq :test
48
- @listener.value.should eq :new_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.should be false
56
+ expect(@listener.notified).to be false
56
57
  @attributes[:test] = :same_value
57
- @listener.notified.should be false
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.should eq [ :larry, :curly, :moe ]
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.should eq [ :larry, :curly, :moe ]
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].should eq 'dumb'
87
- @group[:curly].should eq 'bald'
88
- @group[:moe].should eq 'smart'
89
- @attributes[:larry].should eq 'dumb'
90
- @attributes[:curly].should eq 'bald'
91
- @attributes[:moe].should eq 'smart'
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.should eq %w( dumb bald smart )
96
+ expect(@group.values).to eq %w( dumb bald smart )
96
97
  end
97
98
 
98
99
  end
99
100
 
100
- describe Woyo::Attributes::BooleanGroup do
101
+ describe Woyo::Attributes::Exclusion do
101
102
 
102
103
  before :all do
103
- @group = Woyo::Attributes::BooleanGroup.new Woyo::Attributes::AttributesHash.new, :warm, :cool, :cold
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.should eq :warm
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].should be true
112
- @group[:cool].should be false
113
- @group[:cold].should be false
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].should be @group
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].should be false
125
- @group[:cool].should be false
126
- @group[:cold].should be true
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].should be true
132
- @group[:cool].should be false
133
- @group[:cold].should be false
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::BooleanGroup.new Woyo::Attributes::AttributesHash.new, :yes, :no
138
- @binary_group[:yes].should be true
139
- @binary_group[:no].should be false
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].should be false
142
- @binary_group[:no].should be true
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].should eq true
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.should eq :warm
158
+ expect(@group.value).to eq :warm
158
159
  @group[:cold] = true
159
- @group.value.should eq :cold
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
- it 'has attributes' do
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.should be_instance_of Woyo::World
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.should eq 3
32
- home.ways.keys.should eq [ :up, :down, :out ]
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.should eq home
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.should be_instance_of Woyo::Location
53
- door.to.id.should eq :away
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
- it '#here' do
59
- home = Woyo::Location.new :home
60
- home.here.should be home
61
- end
63
+ context 'items' do
62
64
 
63
- it '#world' do
64
- world = Woyo::World.new
65
- home = Woyo::Location.new :home, context: world
66
- home.world.should eq world
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
- home.characters.size.should eq 1
75
- peter = home.characters[:peter]
76
- peter.should be_instance_of Woyo::Character
77
- peter.location.should be home
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