diff options
Diffstat (limited to 'CLI/ruby/spec')
| -rw-r--r-- | CLI/ruby/spec/game_of_life_spec.rb | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/CLI/ruby/spec/game_of_life_spec.rb b/CLI/ruby/spec/game_of_life_spec.rb index 5c93709..b4c1710 100644 --- a/CLI/ruby/spec/game_of_life_spec.rb +++ b/CLI/ruby/spec/game_of_life_spec.rb @@ -1,7 +1,75 @@ # frozen_string_literal: true RSpec.describe GameOfLife do - it "has a version number" do - expect(GameOfLife::VERSION).not_to be nil + describe ".generate" do + let(:options) do + { + "live-cell" => "L", + "dead-cell" => "D", + "delay" => 100, + "width" => 10, + "height" => 20, + "seed" => 500, + } + end + + context "with options['input']" do + before { options["input"] = "./file.txt" } + + it "defines configurations constants" do + expect(described_class::Cell).to receive(:const_set).with(:LIVE_CELL, "L") + expect(described_class::Cell).to receive(:const_set).with(:DEAD_CELL, "D") + expect(described_class).to receive(:const_set).with(:DELAY, 100.0) + expect(described_class).to receive(:const_set).with(:BANNER, "Input: ./file.txt") + + allow(described_class::Generators::Input).to receive(:new) + described_class.generate(options) + end + + it "calls Generators::Input.new" do + allow(described_class::Cell).to receive(:const_set) + allow(described_class).to receive(:const_set) + + expect(described_class::Generators::Input).to receive(:new).with(options) + described_class.generate(options) + end + end + + context "without options['input']" do + before { options["seed"] = 1337 } + + it "defines configurations constants" do + expect(described_class::Cell).to receive(:const_set).with(:LIVE_CELL, "L") + expect(described_class::Cell).to receive(:const_set).with(:DEAD_CELL, "D") + expect(described_class).to receive(:const_set).with(:DELAY, 100.0) + expect(described_class).to receive(:const_set).with(:BANNER, "Seed: 1337") + + allow(described_class::Generators::Seed).to receive(:new) + described_class.generate(options) + end + + it "calls Generators::Seed.new (and raises error)" do + allow(described_class::Cell).to receive(:const_set) + allow(described_class).to receive(:const_set) + + expect { described_class.generate(options) }.to raise_error(NotImplementedError) + end + end + end + + describe ".run" do + let(:universe) { GameOfLife::Universe.new(width: 3, height: 3) } + + it "calls universe#evolve! and #{described_class}.run" do + # allow kernel loop tiwce + allow(Kernel).to receive(:loop).and_yield.and_yield + + expect(described_class).to receive(:render).with(universe).twice + expect(universe).to receive(:evolve!).twice + + described_class.run(universe) + end end + + describe.pending ".render" end |
