summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--spec/component_manager_spec.rb89
-rw-r--r--spec/entity_manager_spec.rb68
-rw-r--r--spec/spec_helper.rb116
3 files changed, 273 insertions, 0 deletions
diff --git a/spec/component_manager_spec.rb b/spec/component_manager_spec.rb
new file mode 100644
index 0000000..9c53cd2
--- /dev/null
+++ b/spec/component_manager_spec.rb
@@ -0,0 +1,89 @@
+require_relative '../felflame.rb'
+
+describe 'Components' do
+
+ #let :component_manager do
+ # @component_manager ||= FelFlame::Components.new('TestComponents', :param1, param2: 'def')
+ #end
+
+ before :all do
+ @component_manager ||= FelFlame::Components.new('TestComponents', :param1, param2: 'def')
+ end
+
+ before :each do
+ @ent0 = FelFlame::Entities.new
+ @ent1 = FelFlame::Entities.new
+ @ent2 = FelFlame::Entities.new
+ @cmp0 = @component_manager.new
+ @cmp1 = @component_manager.new
+ @cmp2 = @component_manager.new
+ end
+
+ after :each do
+ FelFlame::Entities.each(&:delete)
+ @component_manager.each(&:delete)
+ end
+
+ it 'can delete a component' do
+ component_id = @cmp1.id
+ @ent0.add @cmp1
+
+ expect(@cmp1.delete).to be true
+ expect(@cmp1.id).to be_nil
+ expect(@component_manager[component_id]).to be_nil
+ expect(@cmp1.entities).to eq([])
+ end
+
+ 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
+ FelFlame::Components.each do |component_manager|
+ all_components.delete component_manager.to_s.to_sym
+ end
+ expect(all_components).to eq([])
+ end
+
+ it 'can change params on initialization' do
+ @cmp3 = @component_manager.new(param1: 'ok', param2: 10)
+ expect(@cmp3.attrs).to eq(param1: 'ok', param2: 10, id: @cmp3.id)
+ end
+
+
+ it 'sets default params correctly' do
+ expect(@cmp0.param1).to be_nil
+ expect(@cmp0.param2).to eq('def')
+ expect(@cmp1.param1).to be_nil
+ expect(@cmp1.param2).to eq('def')
+ expect(@cmp2.param1).to be_nil
+ expect(@cmp2.param2).to eq('def')
+ end
+
+ 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.attrs).to eq(param1: 3, param2: 'new', id: 1)
+ 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 'cant overwrite exiting component managers' do
+ expect { FelFlame::Components.new('TestComponents') }.to raise_error(NameError)
+ end
+end
diff --git a/spec/entity_manager_spec.rb b/spec/entity_manager_spec.rb
new file mode 100644
index 0000000..532e583
--- /dev/null
+++ b/spec/entity_manager_spec.rb
@@ -0,0 +1,68 @@
+require_relative '../felflame.rb'
+
+#class EntitiesTest < Minitest::Test
+
+describe 'Entities' do
+
+ #let :component_manager do
+ # @component_manager ||= FelFlame::Components.new('Test', :param1, param2: 'def')
+ #end
+
+ before :all do
+ @component_manager ||= FelFlame::Components.new('TestEntity', :param1, param2: 'def')
+ end
+
+
+ before :each do
+ @ent0 = FelFlame::Entities.new
+ @ent1 = FelFlame::Entities.new
+ @ent2 = FelFlame::Entities.new
+ @cmp0 = @component_manager.new
+ @cmp1 = @component_manager.new
+ @cmp2 = @component_manager.new
+ end
+
+ after :each do
+ FelFlame::Entities.each(&:delete)
+ @component_manager.each(&:delete)
+ 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 '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
+ expect(@ent0.components[@component_manager][0]).to eq(@cmp0.id)
+
+ @ent1.add @cmp1, @cmp2
+ expect(@ent1.components[@component_manager].length).to eq(2)
+ expect(@ent1.components[@component_manager].include?(@cmp1.id)).to be true
+ expect(@ent1.components[@component_manager].include?(@cmp2.id)).to be true
+ end
+
+ it 'can have components removed' do
+ @ent0.add @cmp0
+ expect(@ent0.remove @cmp0).to be true
+ expect(@ent0.components[@component_manager].empty?).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
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..0d826a1
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,116 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# The generated `.rspec` file contains `--require spec_helper` which will cause
+# this file to always be loaded, without a need to explicitly require it in any
+# files.
+#
+# Given that it is always loaded, you are encouraged to keep this file as
+# light-weight as possible. Requiring heavyweight dependencies from this file
+# will add to the boot time of your test suite on EVERY test run, even for an
+# individual file that may not need all of that loaded. Instead, consider making
+# a separate helper file that requires the additional dependencies and performs
+# the additional setup, and require it from the spec files that actually need
+# it.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ require 'simplecov'
+ require 'simplecov-console'
+
+ SimpleCov.start do
+ add_filter 'spec'
+ add_filter 'deprecated'
+ add_group "Ignored Code" do |src_file|
+ open(src_file.filename).grep(/:nocov:/).any?
+ end
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
+ SimpleCov::Formatter::Console,
+ SimpleCov::Formatter::HTMLFormatter,
+ SimpleCov::Formatter::JSONFormatter
+ #SimpleCovSmallBadge::Formatter
+ ])
+ end
+ # rspec-expectations config goes here. You can use an alternate
+ # assertion/expectation library such as wrong or the stdlib/minitest
+ # assertions if you prefer.
+ config.expect_with :rspec do |expectations|
+ # This option will default to `true` in RSpec 4. It makes the `description`
+ # and `failure_message` of custom matchers include text for helper methods
+ # defined using `chain`, e.g.:
+ # be_bigger_than(2).and_smaller_than(4).description
+ # # => "be bigger than 2 and smaller than 4"
+ # ...rather than:
+ # # => "be bigger than 2"
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ # rspec-mocks config goes here. You can use an alternate test double
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
+ config.mock_with :rspec do |mocks|
+ # Prevents you from mocking or stubbing a method that does not exist on
+ # a real object. This is generally recommended, and will default to
+ # `true` in RSpec 4.
+ mocks.verify_partial_doubles = true
+ end
+
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
+ # have no way to turn it off -- the option exists only for backwards
+ # compatibility in RSpec 3). It causes shared context metadata to be
+ # inherited by the metadata hash of host groups and examples, rather than
+ # triggering implicit auto-inclusion in groups with matching metadata.
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+
+ # The settings below are suggested to provide a good initial experience
+ # with RSpec, but feel free to customize to your heart's content.
+=begin
+ # This allows you to limit a spec run to individual examples or groups
+ # you care about by tagging them with `:focus` metadata. When nothing
+ # is tagged with `:focus`, all examples get run. RSpec also provides
+ # aliases for `it`, `describe`, and `context` that include `:focus`
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
+ config.filter_run_when_matching :focus
+
+ # Allows RSpec to persist some state between runs in order to support
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
+ # you configure your source control system to ignore this file.
+ config.example_status_persistence_file_path = "spec/examples.txt"
+
+ # Limits the available syntax to the non-monkey patched syntax that is
+ # recommended. For more details, see:
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
+ config.disable_monkey_patching!
+
+ # This setting enables warnings. It's recommended, but in some cases may
+ # be too noisy due to issues in dependencies.
+ config.warnings = true
+
+ # Many RSpec users commonly either run the entire suite or an individual
+ # file, and it's useful to allow more verbose output when running an
+ # individual spec file.
+ if config.files_to_run.one?
+ # Use the documentation formatter for detailed output,
+ # unless a formatter has already been configured
+ # (e.g. via a command-line flag).
+ config.default_formatter = "doc"
+ end
+
+ # Print the 10 slowest examples and example groups at the
+ # end of the spec run, to help surface which specs are running
+ # particularly slow.
+ config.profile_examples = 10
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = :random
+
+ # Seed global randomization in this process using the `--seed` CLI option.
+ # Setting this allows you to use `--seed` to deterministically reproduce
+ # test failures related to randomization by passing the same `--seed` value
+ # as the one that triggered the failure.
+ Kernel.srand config.seed
+=end
+end