added RSpec and RSpec on Rails

This commit is contained in:
Xin Zheng 2008-01-22 16:39:09 +00:00
parent ddd5b4cf19
commit 3f607d565b
316 changed files with 23828 additions and 0 deletions

View file

@ -0,0 +1,6 @@
$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib')
$:.unshift File.join(File.dirname(__FILE__), '..')
require 'spec'
require 'behaviour/examples/examples'
require 'behaviour/stories/stories'

View file

@ -0,0 +1,3 @@
require 'spec'
require 'behaviour/examples/game_behaviour'
require 'behaviour/examples/grid_behaviour'

View file

@ -0,0 +1,35 @@
require 'life'
describe Game do
it 'should have a grid' do
# given
game = Game.new(5, 5)
# then
game.grid.should be_kind_of(Grid)
end
it 'should create a cell' do
# given
game = Game.new(2, 2)
expected_grid = Grid.from_string( 'X. ..' )
# when
game.create_at(0, 0)
# then
game.grid.should == expected_grid
end
it 'should destroy a cell' do
# given
game = Game.new(2,2)
game.grid = Grid.from_string('X. ..')
# when
game.destroy_at(0,0)
# then
game.grid.should == Grid.from_string('.. ..')
end
end

View file

@ -0,0 +1,66 @@
describe Grid do
it 'should be empty when created' do
# given
expected_contents = [
[0, 0, 0],
[0, 0, 0]
]
grid = Grid.new(2, 3)
# when
contents = grid.contents
# then
contents.should == expected_contents
end
it 'should compare equal based on its contents' do
# given
grid1 = Grid.new(2, 3)
grid2 = Grid.new(2, 3)
# then
grid1.should == grid2
end
it 'should be able to replace its contents' do
# given
grid = Grid.new(2,2)
new_contents = [[0,1,0], [1,0,1]]
# when
grid.contents = new_contents
# then
grid.contents.should == new_contents
grid.rows.should == 2
grid.columns.should == 3
end
it 'should add an organism' do
# given
grid = Grid.new(2, 2)
expected = Grid.new(2, 2)
expected.contents = [[1,0],[0,0]]
# when
grid.create_at(0,0)
# then
grid.should == expected
end
it 'should create itself from a string' do
# given
expected = Grid.new 3, 3
expected.create_at(0,0)
expected.create_at(1,0)
expected.create_at(2,2)
# when
actual = Grid.from_string "X.. X.. ..X"
# then
actual.should == expected
end
end

View file

@ -0,0 +1,21 @@
Story: cells with less than two neighbours die
As a game producer
I want cells with less than two neighbours to die
So that I can illustrate how the game works to people with money
Scenario: cells with zero or one neighbour die
Given the grid looks like
........
.XX.XX..
.XX.....
....X...
........
When the next step occurs
Then the grid should look like
........
.XX.....
.XX.....
........
........

View file

@ -0,0 +1,21 @@
Story: cells with more than three neighbours die
As a game producer
I want cells with more than three neighbours to die
So that I can show the people with money how we are getting on
Scenario: blink
Given the grid looks like
.....
...XX
...XX
.XX..
.XX..
When the next step occurs
Then the grid should look like
.....
...XX
....X
.X...
.XX..

View file

@ -0,0 +1,42 @@
Story: Empty spaces with three neighbours create a cell
As a game producer
I want empty cells with three neighbours to die
So that I have a minimum feature set to ship
Scenario: the glider
Given the grid looks like
...X..
..X...
..XXX.
......
......
When the next step occurs
Then the grid should look like
......
..X.X.
..XX..
...X..
......
When the next step occurs
Then the grid should look like
......
..X...
..X.X.
..XX..
......
When the next step occurs
Then the grid should look like
......
...X..
.XX...
..XX..
......
When the next step occurs
Then the grid should look like
......
..X...
.X....
.XXX..
......

View file

@ -0,0 +1,42 @@
Story: I can create a cell
As a game producer
I want to create a cell
So that I can show the grid to people
Scenario: nothing to see here
Given a 3 x 3 game
Then the grid should look like
...
...
...
Scenario: all on its lonesome
Given a 3 x 3 game
When I create a cell at 1, 1
Then the grid should look like
...
.X.
...
Scenario: the grid has three cells
Given a 3 x 3 game
When I create a cell at 0, 0
and I create a cell at 0, 1
and I create a cell at 2, 2
Then the grid should look like
XX.
...
..X
Scenario: more cells more more
Given the grid has three cells
When I create a celll at 3, 1
Then the grid should look like
XX.
..X
..X

View file

@ -0,0 +1,17 @@
Story: I can kill a cell
As a game producer
I want to kill a cell
So that when I make a mistake I dont have to start again
Scenario: bang youre dead
Given the grid looks like
XX.
.X.
..X
When I destroy the cell at 0, 1
Then the grid should look like
X..
.X.
..X

View file

@ -0,0 +1,53 @@
Story: The grid wraps
As a game player
I want the grid to wrap
So that untidy stuff at the edges is avoided
Scenario: crowded in the corners
Given the grid looks like
X.X
...
X.X
When the next step is taken
Then the grid should look like
X.X
...
X.X
Scenario: the glider returns
Given the glider
......
..X...
.X....
.XXX..
......
When the next step is taken
and the next step is taken
and the next step is taken
and the next step is taken
Then the grid should look like
......
......
.X....
X.....
XXX...
When the next step is taken
Then the grid should look like
.X....
......
......
X.X...
XX....
When the next step is taken
Then the grid should look like
XX....
......
......
X.....
X.X...

View file

@ -0,0 +1,52 @@
require File.join(File.dirname(__FILE__), *%w[helper])
Story "I can create a cell",
%(As a game producer
I want to create a cell
So that I can show the grid to people), :steps_for => :life do
Scenario "nothing to see here" do
Given "a game with dimensions", 3, 3 do |rows,cols|
@game = Game.new(rows,cols)
end
Then "the grid should look like", %(
...
...
...
)
end
Scenario "all on its lonesome" do
Given "a game with dimensions", 2, 2
When "I create a cell at", 1, 1 do |row,col|
@game.create_at(row,col)
end
Then "the grid should look like", %(
..
.X
)
end
Scenario "the grid has three cells" do
Given "a game with dimensions", 3, 3
When "I create a cell at", 0, 0
When "I create a cell at", 0, 1
When "I create a cell at", 2, 2
Then "the grid should look like", %(
XX.
...
..X
)
end
Scenario "more cells more more" do
GivenScenario "the grid has three cells"
When "I create a cell at", 2, 0
Then "the grid should look like", %(
XX.
...
X.X
)
end
end

View file

@ -0,0 +1,6 @@
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.expand_path("#{dir}/../../../../../../rspec/lib"))
require 'spec'
$LOAD_PATH.unshift(File.expand_path("#{dir}/../../"))
require "#{dir}/../../life"
require File.join(File.dirname(__FILE__), *%w[steps])

View file

@ -0,0 +1,26 @@
require File.join(File.dirname(__FILE__), *%w[helper])
Story 'I can kill a cell',
%(As a game producer
I want to kill a cell
So that when I make a mistake I don't have to start again), :steps_for => :life do
Scenario "bang, you're dead" do
Given 'a game that looks like', %(
XX.
.X.
..X
) do |dots|
@game = Game.from_string dots
end
When 'I destroy the cell at', 0, 1 do |row,col|
@game.destroy_at(row,col)
end
Then 'the grid should look like', %(
X..
.X.
..X
)
end
end

View file

@ -0,0 +1,5 @@
steps_for :life do
Then "the grid should look like" do |dots|
@game.grid.should == Grid.from_string(dots)
end
end

View file

@ -0,0 +1,3 @@
require File.join(File.dirname(__FILE__), *%w[helper])
require 'behaviour/stories/create_a_cell'
require 'behaviour/stories/kill_a_cell'

View file

@ -0,0 +1,22 @@
Story: Show the game field
As a game player
I want to see the field
so that I can observe the progress of the organisms
Scenario: an empty field
Given a new game starts
When the game displays the field
Then the field should be empty
StoryBuilder story = stories.createStory().called("a story")
.asA("person")
.iWant("to do something")
.soThat("I can rule the world");
story.addScenario().called("happy path").as()
.given("some context")
.when("some event happens")
.then("expect some outcome");