main
1describe World do
2 subject { World.new(cells) }
3 let(:cells) { [neighbor, other_cell] }
4 let(:neighbor) { double }
5 let(:other_cell) { double }
6
7 context "#neighbors_for" do
8 let(:cell) { Cell.new }
9
10 before :each do
11 cell.stub(:neighbor?).with(neighbor).and_return(true)
12 cell.stub(:neighbor?).with(other_cell).and_return(false)
13 end
14
15 it "returns the neighboring cells" do
16 expect(subject.neighbors_for(cell)).to include(neighbor)
17 end
18
19 it "does not return cells that are not neighbors" do
20 expect(subject.neighbors_for(cell)).to_not include(other_cell)
21 end
22 end
23
24 context "#next_generation!" do
25 subject { World.new([cell]) }
26 let(:cell) { double(spawn: true) }
27
28 it "visits each cell" do
29 subject.next_generation!
30 expect(cell).to have_received(:spawn).with(subject)
31 end
32 end
33
34 context "#empty?" do
35 context "when there are no living cells" do
36 it "returns true" do
37 neighbor.stub(:alive?).and_return(false)
38 other_cell.stub(:alive?).and_return(false)
39 expect(subject).to be_empty
40 end
41 end
42
43 context "when there is at least one living cell" do
44 it "returns false" do
45 neighbor.stub(:alive?).and_return(false)
46 other_cell.stub(:alive?).and_return(true)
47 expect(subject).to_not be_empty
48 end
49 end
50 end
51end