# frozen_string_literal: true RSpec.describe GameOfLife do 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