added RSpec and RSpec on Rails
This commit is contained in:
parent
ddd5b4cf19
commit
3f607d565b
316 changed files with 23828 additions and 0 deletions
21
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/README.txt
vendored
Normal file
21
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/README.txt
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
John Conway's Game of Life
|
||||
|
||||
The Rules
|
||||
---------
|
||||
The Game of Life was invented by John Conway (as you might have gathered).
|
||||
The game is played on a field of cells, each of which has eight neighbors (adjacent cells).
|
||||
A cell is either occupied (by an organism) or not.
|
||||
The rules for deriving a generation from the previous one are these:
|
||||
|
||||
Survival
|
||||
--------
|
||||
If an occupied cell has 2 or 3 neighbors, the organism survives to the next generation.
|
||||
|
||||
Death
|
||||
-----
|
||||
If an occupied cell has 0, 1, 4, 5, 6, 7, or 8 occupied neighbors, the organism dies
|
||||
(0, 1: of loneliness; 4 thru 8: of overcrowding).
|
||||
|
||||
Birth
|
||||
-----
|
||||
If an unoccupied cell has 3 occupied neighbors, it becomes occupied.
|
6
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/everything.rb
vendored
Normal file
6
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/everything.rb
vendored
Normal 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'
|
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/examples.rb
vendored
Normal file
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/examples.rb
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
require 'spec'
|
||||
require 'behaviour/examples/game_behaviour'
|
||||
require 'behaviour/examples/grid_behaviour'
|
35
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb
vendored
Normal file
35
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb
vendored
Normal 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
|
66
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
vendored
Normal file
66
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
vendored
Normal 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
|
|
@ -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.....
|
||||
........
|
||||
........
|
|
@ -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..
|
|
@ -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..
|
||||
......
|
42
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story
vendored
Normal file
42
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story
vendored
Normal 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
|
17
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story
vendored
Normal file
17
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story
vendored
Normal 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
|
53
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story
vendored
Normal file
53
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story
vendored
Normal 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...
|
||||
|
||||
|
52
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb
vendored
Normal file
52
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb
vendored
Normal 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
|
6
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/helper.rb
vendored
Normal file
6
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/helper.rb
vendored
Normal 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])
|
26
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb
vendored
Normal file
26
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb
vendored
Normal 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
|
5
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/steps.rb
vendored
Normal file
5
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/steps.rb
vendored
Normal 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
|
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/stories.rb
vendored
Normal file
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/stories.rb
vendored
Normal 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'
|
22
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/stories.txt
vendored
Normal file
22
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/stories/stories.txt
vendored
Normal 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");
|
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life.rb
vendored
Normal file
3
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life.rb
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
$: << File.dirname(__FILE__)
|
||||
require 'life/game'
|
||||
require 'life/grid'
|
23
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life/game.rb
vendored
Normal file
23
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life/game.rb
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Game
|
||||
attr_accessor :grid
|
||||
def initialize(rows,cols)
|
||||
@grid = Grid.new(rows, cols)
|
||||
end
|
||||
|
||||
def create_at(row,col)
|
||||
@grid.create_at(row,col)
|
||||
end
|
||||
|
||||
def destroy_at(row,col)
|
||||
@grid.destroy_at(row, col)
|
||||
end
|
||||
|
||||
def self.from_string(dots)
|
||||
grid = Grid.from_string(dots)
|
||||
game = new(grid.rows, grid.columns)
|
||||
game.instance_eval do
|
||||
@grid = grid
|
||||
end
|
||||
return game
|
||||
end
|
||||
end
|
43
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life/grid.rb
vendored
Normal file
43
vendor/gems/rspec-1.1.2/examples/stories/game-of-life/life/grid.rb
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
class Grid
|
||||
|
||||
attr_accessor :contents
|
||||
|
||||
def initialize(rows, cols)
|
||||
@contents = []
|
||||
rows.times do @contents << [0] * cols end
|
||||
end
|
||||
|
||||
def rows
|
||||
@contents.size
|
||||
end
|
||||
|
||||
def columns
|
||||
@contents[0].size
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.contents == other.contents
|
||||
end
|
||||
|
||||
def create_at(row,col)
|
||||
@contents[row][col] = 1
|
||||
end
|
||||
|
||||
def destroy_at(row,col)
|
||||
@contents[row][col] = 0
|
||||
end
|
||||
|
||||
def self.from_string(str)
|
||||
row_strings = str.split(' ')
|
||||
grid = new(row_strings.size, row_strings[0].size)
|
||||
|
||||
row_strings.each_with_index do |row, row_index|
|
||||
row_chars = row.split(//)
|
||||
row_chars.each_with_index do |col_char, col_index|
|
||||
grid.create_at(row_index, col_index) if col_char == 'X'
|
||||
end
|
||||
end
|
||||
return grid
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue