1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# 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
|