diff options
| author | realtradam <[email protected]> | 2021-12-30 07:28:14 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-12-30 07:28:14 -0500 |
| commit | d03ce21592062aed27a571fda60483fcb3fba764 (patch) | |
| tree | b82c99051b378c18ad4a8af98292681869dfa5a7 /spec | |
| parent | 38e1a046dcc0ecf5e3ec672ca466f02038b86a02 (diff) | |
| download | FelECS-arry.tar.gz FelECS-arry.zip | |
.arry
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/component_manager_spec.rb | 28 | ||||
| -rw-r--r-- | spec/entity_manager_spec.rb | 31 |
2 files changed, 56 insertions, 3 deletions
diff --git a/spec/component_manager_spec.rb b/spec/component_manager_spec.rb index d05a8a7..6fedf78 100644 --- a/spec/component_manager_spec.rb +++ b/spec/component_manager_spec.rb @@ -11,6 +11,8 @@ 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 @@ -20,10 +22,23 @@ 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 @@ -37,6 +52,19 @@ describe 'Components' 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) + end + it 'can delete a component' do #component_id = @cmp1.id @ent0.add @cmp1 diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb index 6d31dd2..424b162 100644 --- a/spec/entity_manager_spec.rb +++ b/spec/entity_manager_spec.rb @@ -15,6 +15,8 @@ describe 'Entities' do before :each do + @orig_stderr = $stderr + $stderr = StringIO.new @ent0 = FelFlame::Entities.new @ent1 = FelFlame::Entities.new @ent2 = FelFlame::Entities.new @@ -24,10 +26,30 @@ describe 'Entities' do end after :each do + $stderr = @orig_stderr FelFlame::Entities.reverse_each(&:delete) @component_manager.reverse_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 @@ -79,7 +101,10 @@ describe 'Entities' do @ent0.add @cmp0 expect(@ent0.remove @cmp0).to be true expect(@cmp0.entities.empty?).to be true - expect(@ent0.components[@component_manager].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 end it 'can have many components added then removed' do @@ -99,8 +124,8 @@ describe 'Entities' do @component_manager.reverse_each(&:delete) expect(@component_manager.length).to eq(0) expect(@component_manager.empty?).to be true - expect(@ent0.components).to eq({@component_manager => []}) - expect(@ent2.components).to eq({@component_manager => []}) + expect(@ent0.components).to eq({}) + expect(@ent2.components).to eq({}) FelFlame::Entities.reverse_each(&:delete) expect(FelFlame::Entities.empty?).to be true end |
