mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-09 06:02:36 +01:00
Added Rspec and Webrat plugins and started porting Selenium on Rails tests to Rspec Plain Text Stories driving Webrat driving Selenium.
This commit is contained in:
parent
7b432a74ed
commit
2c09db45c5
602 changed files with 47788 additions and 29 deletions
13
vendor/plugins/rspec/examples/stories/adder.rb
vendored
Normal file
13
vendor/plugins/rspec/examples/stories/adder.rb
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Adder
|
||||
def initialize
|
||||
@addends = []
|
||||
end
|
||||
|
||||
def <<(val)
|
||||
@addends << val
|
||||
end
|
||||
|
||||
def sum
|
||||
@addends.inject(0) { |sum_so_far, val| sum_so_far + val }
|
||||
end
|
||||
end
|
||||
34
vendor/plugins/rspec/examples/stories/addition
vendored
Normal file
34
vendor/plugins/rspec/examples/stories/addition
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
This is a story about a calculator. The text up here above the Story: declaration
|
||||
won't be processed, so you can write whatever you wish!
|
||||
|
||||
Story: simple addition
|
||||
|
||||
As an accountant
|
||||
I want to add numbers
|
||||
So that I can count beans
|
||||
|
||||
Scenario: add one plus one
|
||||
Given an addend of 1
|
||||
And an addend of 1
|
||||
|
||||
When the addends are addeds
|
||||
|
||||
Then the sum should be 3
|
||||
And the corks should be popped
|
||||
|
||||
Scenario: add two plus five
|
||||
Given an addend of 2
|
||||
And an addend of 5
|
||||
|
||||
When the addends are added
|
||||
|
||||
Then the sum should be 7
|
||||
Then it should snow
|
||||
|
||||
Scenario: add three more
|
||||
GivenScenario add two plus five
|
||||
And an addend of 3
|
||||
|
||||
When the addends are added
|
||||
|
||||
Then the sum should be 10
|
||||
9
vendor/plugins/rspec/examples/stories/addition.rb
vendored
Normal file
9
vendor/plugins/rspec/examples/stories/addition.rb
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
require File.join(File.dirname(__FILE__), "helper")
|
||||
require File.join(File.dirname(__FILE__), "adder")
|
||||
|
||||
# with_steps_for :addition, :more_addition do
|
||||
with_steps_for :addition, :more_addition do
|
||||
# Then("the corks should be popped") { }
|
||||
run File.expand_path(__FILE__).gsub(".rb","")
|
||||
end
|
||||
|
||||
65
vendor/plugins/rspec/examples/stories/calculator.rb
vendored
Normal file
65
vendor/plugins/rspec/examples/stories/calculator.rb
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
$:.push File.join(File.dirname(__FILE__), *%w[.. .. lib])
|
||||
require 'spec'
|
||||
|
||||
class AdditionMatchers < Spec::Story::StepGroup
|
||||
steps do |add|
|
||||
add.given("an addend of $addend") do |addend|
|
||||
@adder ||= Adder.new
|
||||
@adder << addend.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
steps = AdditionMatchers.new do |add|
|
||||
add.then("the sum should be $sum") do |sum|
|
||||
@sum.should == sum.to_i
|
||||
end
|
||||
end
|
||||
|
||||
steps.when("they are added") do
|
||||
@sum = @adder.sum
|
||||
end
|
||||
|
||||
# This Story uses steps (see above) instead of blocks
|
||||
# passed to Given, When and Then
|
||||
|
||||
Story "addition", %{
|
||||
As an accountant
|
||||
I want to add numbers
|
||||
So that I can count some beans
|
||||
}, :steps_for => steps do
|
||||
Scenario "2 + 3" do
|
||||
Given "an addend of 2"
|
||||
And "an addend of 3"
|
||||
When "they are added"
|
||||
Then "the sum should be 5"
|
||||
end
|
||||
|
||||
# This scenario uses GivenScenario, which silently runs
|
||||
# all the steps in a previous scenario.
|
||||
|
||||
Scenario "add 4 more" do
|
||||
GivenScenario "2 + 3"
|
||||
Given "an addend of 4"
|
||||
When "they are added"
|
||||
Then "the sum should be 9"
|
||||
end
|
||||
end
|
||||
|
||||
# And the class that makes the story pass
|
||||
|
||||
class Adder
|
||||
def << addend
|
||||
addends << addend
|
||||
end
|
||||
|
||||
def sum
|
||||
@addends.inject(0) do |result, addend|
|
||||
result + addend.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def addends
|
||||
@addends ||= []
|
||||
end
|
||||
end
|
||||
5
vendor/plugins/rspec/examples/stories/game-of-life/.loadpath
vendored
Normal file
5
vendor/plugins/rspec/examples/stories/game-of-life/.loadpath
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<loadpath>
|
||||
<pathentry path="" type="src"/>
|
||||
<pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
|
||||
</loadpath>
|
||||
21
vendor/plugins/rspec/examples/stories/game-of-life/README.txt
vendored
Normal file
21
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/everything.rb
vendored
Normal file
6
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/examples/examples.rb
vendored
Normal file
3
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb
vendored
Normal file
35
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
vendored
Normal file
66
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story
vendored
Normal file
42
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story
vendored
Normal file
17
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story
vendored
Normal file
53
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb
vendored
Normal file
52
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/helper.rb
vendored
Normal file
6
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb
vendored
Normal file
26
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/steps.rb
vendored
Normal file
5
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/stories.rb
vendored
Normal file
3
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/behaviour/stories/stories.txt
vendored
Normal file
22
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/life.rb
vendored
Normal file
3
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/life/game.rb
vendored
Normal file
23
vendor/plugins/rspec/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/plugins/rspec/examples/stories/game-of-life/life/grid.rb
vendored
Normal file
43
vendor/plugins/rspec/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
|
||||
9
vendor/plugins/rspec/examples/stories/helper.rb
vendored
Normal file
9
vendor/plugins/rspec/examples/stories/helper.rb
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
||||
require 'spec/story'
|
||||
|
||||
# won't have to do this once plain_text_story_runner is moved into the library
|
||||
# require File.join(File.dirname(__FILE__), "plain_text_story_runner")
|
||||
|
||||
Dir[File.join(File.dirname(__FILE__), "steps/*.rb")].each do |file|
|
||||
require file
|
||||
end
|
||||
18
vendor/plugins/rspec/examples/stories/steps/addition_steps.rb
vendored
Normal file
18
vendor/plugins/rspec/examples/stories/steps/addition_steps.rb
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
require File.expand_path("#{File.dirname(__FILE__)}/../helper")
|
||||
|
||||
# This creates steps for :addition
|
||||
steps_for(:addition) do
|
||||
Given("an addend of $addend") do |addend|
|
||||
@adder ||= Adder.new
|
||||
@adder << addend.to_i
|
||||
end
|
||||
end
|
||||
|
||||
# This appends to them
|
||||
steps_for(:addition) do
|
||||
When("the addends are added") { @sum = @adder.sum }
|
||||
end
|
||||
|
||||
steps_for(:more_addition) do
|
||||
Then("the sum should be $sum") { |sum| @sum.should == sum.to_i }
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue