changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1describe Grid do
2 it 'should be empty when created' do
3 # given
4 expected_contents = [
5 [0, 0, 0],
6 [0, 0, 0]
7 ]
8 grid = Grid.new(2, 3)
9
10 # when
11 contents = grid.contents
12
13 # then
14 contents.should == expected_contents
15 end
16
17 it 'should compare equal based on its contents' do
18 # given
19 grid1 = Grid.new(2, 3)
20 grid2 = Grid.new(2, 3)
21
22 # then
23 grid1.should == grid2
24 end
25
26 it 'should be able to replace its contents' do
27 # given
28 grid = Grid.new(2,2)
29 new_contents = [[0,1,0], [1,0,1]]
30
31 # when
32 grid.contents = new_contents
33
34 # then
35 grid.contents.should == new_contents
36 grid.rows.should == 2
37 grid.columns.should == 3
38 end
39
40 it 'should add an organism' do
41 # given
42 grid = Grid.new(2, 2)
43 expected = Grid.new(2, 2)
44 expected.contents = [[1,0],[0,0]]
45
46 # when
47 grid.create_at(0,0)
48
49 # then
50 grid.should == expected
51 end
52
53 it 'should create itself from a string' do
54 # given
55 expected = Grid.new 3, 3
56 expected.create_at(0,0)
57 expected.create_at(1,0)
58 expected.create_at(2,2)
59
60 # when
61 actual = Grid.from_string "X.. X.. ..X"
62
63 # then
64 actual.should == expected
65 end
66end