summaryrefslogtreecommitdiffhomepage
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/component_manager_spec.rb94
-rw-r--r--spec/entity_manager_spec.rb91
-rw-r--r--spec/scene_manager_spec.rb2
-rw-r--r--spec/stage_manager_spec.rb2
-rw-r--r--spec/system_manager_spec.rb16
5 files changed, 54 insertions, 151 deletions
diff --git a/spec/component_manager_spec.rb b/spec/component_manager_spec.rb
index 6fedf78..d99d744 100644
--- a/spec/component_manager_spec.rb
+++ b/spec/component_manager_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../lib/felflame.rb'
+require 'felflame'
describe 'Components' do
@@ -11,8 +11,6 @@ describe 'Components' do
end
before :each do
- @orig_stderr = $stderr
- $stderr = StringIO.new
@ent0 = FelFlame::Entities.new
@ent1 = FelFlame::Entities.new
@ent2 = FelFlame::Entities.new
@@ -22,61 +20,21 @@ describe 'Components' do
end
after :each do
- $stderr = @orig_stderr
- FelFlame::Entities.reverse_each(&:delete)
- @component_manager.reverse_each(&:delete)
- end
-
- it 'can get a single entity' do
- @cmp0.entity
- $stderr.rewind
- $stderr.string.chomp.should eq("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
- @ent0.add @cmp0
- expect(@cmp0.entity).to eq(@ent0)
- @ent1.add @cmp0
- @cmp0.entity
- $stderr.rewind
- $stderr.string.chomp.should eq("This component belongs to MANY entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
- end
-
- it 'responds to array methods' do
- expect(@component_manager.respond_to?(:[])).to be true
- expect(@component_manager.respond_to?(:each)).to be true
- expect(@component_manager.respond_to?(:filter)).to be true
- expect(@component_manager.respond_to?(:first)).to be true
- expect(@component_manager.respond_to?(:last)).to be true
- expect(@component_manager.respond_to?(:somethingwrong)).to be false
- end
-
- it 'dont respond to missing methods' do
- expect { @component_manager.somethingwrong }.to raise_error(NoMethodError)
- end
-
- it 'Component module responds to array methods' do
- expect(FelFlame::Components.respond_to?(:[])).to be true
- expect(FelFlame::Components.respond_to?(:each)).to be true
- expect(FelFlame::Components.respond_to?(:filter)).to be true
- expect(FelFlame::Components.respond_to?(:first)).to be true
- expect(FelFlame::Components.respond_to?(:last)).to be true
- expect(FelFlame::Components.respond_to?(:somethingwrong)).to be false
- end
-
- it 'Component module doesnt respond to missing methods' do
- expect { FelFlame::Components.somethingwrong }.to raise_error(NoMethodError)
+ FelFlame::Entities.each(&:delete)
+ @component_manager.each(&:delete)
end
it 'can delete a component' do
- #component_id = @cmp1.id
+ component_id = @cmp1.id
@ent0.add @cmp1
- length = @component_manager.length
+
expect(@cmp1.delete).to be true
- expect(@component_manager.length).to eq(length-1)
- #expect(@cmp1.id).to be_nil
- #expect(@component_manager[component_id]).to be_nil
+ expect(@cmp1.id).to be_nil
+ expect(@component_manager[component_id]).to be_nil
expect(@cmp1.entities).to eq([])
end
- it 'can iterate component managers' do
+ it 'can iterate over all component managers' do
all_components = FelFlame::Components.constants
expect(all_components.length).to be > 0
expect(FelFlame::Components.each).to be_an Enumerator
@@ -88,7 +46,7 @@ describe 'Components' do
it 'can change params on initialization' do
@cmp3 = @component_manager.new(param1: 'ok', param2: 10)
- expect(@cmp3.to_h).to eq(param1: 'ok', param2: 10)
+ expect(@cmp3.attrs).to eq(param1: 'ok', param2: 10, id: @cmp3.id)
end
@@ -101,33 +59,29 @@ describe 'Components' do
expect(@cmp2.param2).to eq('def')
end
- it 'can read attributes' do
- expect(@cmp0.to_h).to eq(param2: 'def')
- expect(@cmp1.to_h).to eq(param2: 'def')
- expect(@cmp2.to_h).to eq(param2: 'def')
+ it 'can read attrs' do
+ expect(@cmp0.attrs).to eq(param2: 'def', id: 0)
+ expect(@cmp1.attrs).to eq(param2: 'def', id: 1)
+ expect(@cmp2.attrs).to eq(param2: 'def', id: 2)
end
it 'can set attrs' do
expect(@cmp0.param1 = 4).to eq(4)
expect(@cmp1.update_attrs(param1: 3, param2: 'new')).to eq(param1: 3, param2: 'new')
- expect(@cmp1.to_h).to eq(param1: 3, param2: 'new')
+ expect(@cmp1.attrs).to eq(param1: 3, param2: 'new', id: 1)
end
- it 'can be used as a singleton' do
- expect(@component_manager.first).to eq(@cmp0)
+ it 'can be accessed' do
+ expect(@cmp0).to eq(@component_manager[0])
+ expect(@cmp1).to eq(@component_manager[1])
+ expect(@cmp2).to eq(@component_manager[2])
end
- #it 'can be accessed' do
- # expect(@cmp0).to eq(@component_manager[0])
- # expect(@cmp1).to eq(@component_manager[1])
- # expect(@cmp2).to eq(@component_manager[2])
- #end
-
- #it 'can get id from to_i' do
- # expect(@cmp0.id).to eq(@cmp0.to_i)
- # expect(@cmp1.id).to eq(@cmp1.to_i)
- # expect(@cmp2.id).to eq(@cmp2.to_i)
- #end
+ it 'can get id from to_i' do
+ expect(@cmp0.id).to eq(@cmp0.to_i)
+ expect(@cmp1.id).to eq(@cmp1.to_i)
+ expect(@cmp2.id).to eq(@cmp2.to_i)
+ end
it 'cant overwrite exiting component managers' do
FelFlame::Components.new('TestComponent1')
@@ -135,7 +89,7 @@ describe 'Components' do
end
it 'can\'t create an attribute when its name is an existing method' do
- #expect { FelFlame::Components.new('TestComponent2', :id) }.to raise_error(NameError)
+ expect { FelFlame::Components.new('TestComponent2', :id) }.to raise_error(NameError)
expect { FelFlame::Components.new('TestComponent2', :addition_triggers) }.to raise_error(NameError)
expect { FelFlame::Components.new('TestComponent2', :removal_triggers) }.to raise_error(NameError)
expect { FelFlame::Components.new('TestComponent2', :attr_triggers) }.to raise_error(NameError)
diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb
index 424b162..ef638c0 100644
--- a/spec/entity_manager_spec.rb
+++ b/spec/entity_manager_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../lib/felflame.rb'
+require 'felflame'
#class EntitiesTest < Minitest::Test
@@ -9,14 +9,11 @@ describe 'Entities' do
#end
before :all do
- $VERBOSE = nil
@component_manager ||= FelFlame::Components.new('TestEntity', :param1, param2: 'def')
end
before :each do
- @orig_stderr = $stderr
- $stderr = StringIO.new
@ent0 = FelFlame::Entities.new
@ent1 = FelFlame::Entities.new
@ent2 = FelFlame::Entities.new
@@ -26,60 +23,26 @@ describe 'Entities' do
end
after :each do
- $stderr = @orig_stderr
- FelFlame::Entities.reverse_each(&:delete)
- @component_manager.reverse_each(&:delete)
+ FelFlame::Entities.each(&:delete)
+ @component_manager.each(&:delete)
end
- it 'can get a single component' do
- expect { @ent0.component[@component_manager] }.to raise_error(RuntimeError)
- #$stderr.rewind
- #$stderr.string.chomp.should eq("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
- @ent0.add @cmp0
- expect(@ent0.component[@component_manager]).to eq(@cmp0)
- expect(@ent0.component[@component_manager]).to eq(@ent0.component(@component_manager))
- @ent0.add @cmp1
- @ent0.component[@component_manager]
- $stderr.rewind
- $stderr.string.chomp.should eq("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
- @ent0.components[@component_manager].reverse_each do |component|
- @ent0.remove component
- end
- expect { @ent0.component[@component_manager] }.to raise_error(RuntimeError)
- end
-
-
-
- it 'responds to array methods' do
- expect(FelFlame::Entities.respond_to?(:[])).to be true
- expect(FelFlame::Entities.respond_to?(:each)).to be true
- expect(FelFlame::Entities.respond_to?(:filter)).to be true
- expect(FelFlame::Entities.respond_to?(:first)).to be true
- expect(FelFlame::Entities.respond_to?(:last)).to be true
- expect(FelFlame::Entities.respond_to?(:somethingwrong)).to be false
- end
-
- it 'dont respond to missing methods' do
- expect { FelFlame::Entities.somethingwrong }.to raise_error(NoMethodError)
- end
-
-
it 'won\'t add duplicate entities' do
@ent0.add @cmp0, @cmp0, @cmp1, @cmp1
expect(@ent0.components[@component_manager].count).to eq(2)
end
- #it 'has correct ID\'s' do
- # expect(@ent0.id).to eq(0)
- # expect(@ent1.id).to eq(1)
- # expect(@ent2.id).to eq(2)
- #end
+ it 'has correct ID\'s' do
+ expect(@ent0.id).to eq(0)
+ expect(@ent1.id).to eq(1)
+ expect(@ent2.id).to eq(2)
+ end
- #it 'can be accessed' do
- # expect(@ent0).to eq(FelFlame::Entities[0])
- # expect(@ent1).to eq(FelFlame::Entities[1])
- # expect(@ent2).to eq(FelFlame::Entities[2])
- #end
+ it 'can be accessed' do
+ expect(@ent0).to eq(FelFlame::Entities[0])
+ expect(@ent1).to eq(FelFlame::Entities[1])
+ expect(@ent2).to eq(FelFlame::Entities[2])
+ end
it 'can have components attached' do
@ent0.add @cmp0
@@ -91,20 +54,17 @@ describe 'Entities' do
expect(@ent1.components[@component_manager].include?(@cmp2)).to be true
end
- #it 'can get id from to_i' do
- # expect(@ent0.id).to eq(@ent0.to_i)
- # expect(@ent1.id).to eq(@ent1.to_i)
- # expect(@ent2.id).to eq(@ent2.to_i)
- #end
+ it 'can get id from to_i' do
+ expect(@ent0.id).to eq(@ent0.to_i)
+ expect(@ent1.id).to eq(@ent1.to_i)
+ expect(@ent2.id).to eq(@ent2.to_i)
+ end
it 'can have components removed' do
@ent0.add @cmp0
expect(@ent0.remove @cmp0).to be true
expect(@cmp0.entities.empty?).to be true
- expect(@ent0.components[@component_manager].nil?).to be true
- @ent0.add @cmp0
- @cmp0.delete
- expect(@ent0.components[@component_manager].nil?).to be true
+ expect(@ent0.components[@component_manager].empty?).to be true
end
it 'can have many components added then removed' do
@@ -121,12 +81,11 @@ describe 'Entities' do
expect(@cmp2.entities).to eq([@ent0,@ent2])
@cmp1.delete
expect(@ent0.components).to eq({@component_manager => [@cmp0,@cmp2]})
- @component_manager.reverse_each(&:delete)
- expect(@component_manager.length).to eq(0)
- expect(@component_manager.empty?).to be true
- expect(@ent0.components).to eq({})
- expect(@ent2.components).to eq({})
- FelFlame::Entities.reverse_each(&:delete)
- expect(FelFlame::Entities.empty?).to be true
+ @component_manager.each(&:delete)
+ expect(@component_manager.each.to_a).to eq([])
+ expect(@ent0.components).to eq({@component_manager => []})
+ expect(@ent2.components).to eq({@component_manager => []})
+ FelFlame::Entities.each(&:delete)
+ expect(FelFlame::Entities.each.to_a).to eq([])
end
end
diff --git a/spec/scene_manager_spec.rb b/spec/scene_manager_spec.rb
index 65666c7..f2aee01 100644
--- a/spec/scene_manager_spec.rb
+++ b/spec/scene_manager_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../lib/felflame.rb'
+require 'felflame'
#class EntitiesTest < Minitest::Test
diff --git a/spec/stage_manager_spec.rb b/spec/stage_manager_spec.rb
index 0aa8690..ed1125c 100644
--- a/spec/stage_manager_spec.rb
+++ b/spec/stage_manager_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../lib/felflame.rb'
+require 'felflame'
#class EntitiesTest < Minitest::Test
diff --git a/spec/system_manager_spec.rb b/spec/system_manager_spec.rb
index 3d2e3dc..f9df439 100644
--- a/spec/system_manager_spec.rb
+++ b/spec/system_manager_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../lib/felflame.rb'
+require 'felflame'
describe 'Components' do
@@ -73,16 +73,6 @@ describe 'Components' do
expect(second.health).to eq(init2 - (multiple * 10))
end
- it 'can clear triggers from components and systems' do
- @cmp0 = @component_manager.new
- @system.trigger_when_added @cmp0
- expect(@cmp0.addition_triggers.length).to eq(1)
- expect(@system.addition_triggers.length).to eq(1)
- expect(@cmp0.delete).to be true
- expect(@cmp0.addition_triggers.length).to eq(0)
- expect(@system.addition_triggers.length).to eq(0)
- end
-
it 'can trigger when a single Component is added' do
@cmp0 = @component_manager.new
@cmp1 = @component_manager.new health: 20
@@ -336,7 +326,7 @@ describe 'Components' do
expect(@cmp0.health).to eq(10)
expect(@cmp1.health).to eq(20)
end
-
+
it 'can clear addition_trigger, with component' do
@cmp0 = @component_manager.new health: 10
@cmp1 = @component_manager.new health: 20
@@ -379,7 +369,7 @@ describe 'Components' do
expect(@cmp0.health).to eq(10)
expect(@cmp1.health).to eq(20)
end
-
+
it 'can clear removal_trigger, with component' do
@cmp0 = @component_manager.new health: 10
@cmp1 = @component_manager.new health: 20