rbehave 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +5 -0
- data/Manifest.txt +44 -17
- data/NOTES.txt +2 -7
- data/behaviour/everything.rb +1 -1
- data/behaviour/examples/{everything.rb → examples.rb} +0 -0
- data/behaviour/examples/rbehave/documenter/plain_text_documenter_behaviour.rb +1 -0
- data/behaviour/examples/rbehave/given_scenario_behaviour.rb +26 -0
- data/behaviour/examples/rbehave/runner/options_behaviour.rb +39 -0
- data/behaviour/examples/rbehave/runner/runner_behaviour.rb +39 -0
- data/behaviour/examples/rbehave/runner/story_runner_behaviour.rb +58 -2
- data/behaviour/examples/rbehave/simple_step_behaviour.rb +35 -0
- data/behaviour/examples/rbehave/step_mother_behaviour.rb +32 -0
- data/behaviour/examples/rbehave/world_behaviour.rb +44 -5
- data/behaviour/examples/rspec_adapter.rb +3 -1
- data/examples/game-of-life/.loadpath +5 -0
- data/examples/game-of-life/.project +18 -0
- data/examples/game-of-life/README.txt +21 -0
- data/examples/game-of-life/behaviour/everything.rb +2 -0
- data/examples/game-of-life/behaviour/examples/examples.rb +2 -0
- data/examples/game-of-life/behaviour/examples/game_behaviour.rb +17 -0
- data/examples/game-of-life/behaviour/examples/grid_behaviour.rb +68 -0
- data/examples/game-of-life/behaviour/examples/helper.rb +2 -0
- data/examples/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +21 -0
- data/examples/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +21 -0
- data/examples/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +42 -0
- data/examples/game-of-life/behaviour/stories/ICanCreateACell.story +42 -0
- data/examples/game-of-life/behaviour/stories/ICanKillACell.story +17 -0
- data/examples/game-of-life/behaviour/stories/TheGridWraps.story +53 -0
- data/examples/game-of-life/behaviour/stories/create_a_cell.rb +58 -0
- data/examples/game-of-life/behaviour/stories/stories.txt +22 -0
- data/examples/game-of-life/life.rb +2 -0
- data/examples/game-of-life/life/game.rb +6 -0
- data/examples/game-of-life/life/grid.rb +38 -0
- data/lib/rbehave.rb +6 -71
- data/lib/rbehave/documenter/plain_text_documenter.rb +2 -2
- data/lib/rbehave/exceptions.rb +3 -3
- data/lib/rbehave/given_scenario.rb +12 -0
- data/lib/rbehave/runner.rb +52 -0
- data/lib/rbehave/runner/options.rb +26 -0
- data/lib/rbehave/runner/story_runner.rb +26 -5
- data/lib/rbehave/simple_step.rb +14 -0
- data/lib/rbehave/step_mother.rb +19 -0
- data/lib/rbehave/story.rb +8 -3
- data/lib/rbehave/version.rb +1 -1
- data/lib/rbehave/world.rb +31 -23
- metadata +47 -19
- data/Rakefile +0 -54
@@ -5,7 +5,7 @@ require 'mocha'
|
|
5
5
|
# replace rspec's mocks with mocha
|
6
6
|
Spec::Runner::configuration.mock_with :mocha
|
7
7
|
|
8
|
-
# add ensure_that(..)
|
8
|
+
# add ensure_that(..)
|
9
9
|
module Spec::Expectations::ObjectExpectations
|
10
10
|
def ensure_that(obj, expr)
|
11
11
|
obj.should expr
|
@@ -74,6 +74,8 @@ def is_a(type)
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
alias :is_an :is_a
|
78
|
+
|
77
79
|
def matches(pattern)
|
78
80
|
return Matcher.new("string matching #{pattern}") do |actual|
|
79
81
|
actual =~ pattern
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>game-of-life</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
<project>rbehave</project>
|
7
|
+
</projects>
|
8
|
+
<buildSpec>
|
9
|
+
<buildCommand>
|
10
|
+
<name>org.rubypeople.rdt.core.rubybuilder</name>
|
11
|
+
<arguments>
|
12
|
+
</arguments>
|
13
|
+
</buildCommand>
|
14
|
+
</buildSpec>
|
15
|
+
<natures>
|
16
|
+
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
John Conway's Game of Life
|
2
|
+
|
3
|
+
The Rules
|
4
|
+
---------
|
5
|
+
The Game of Life was invented by John Conway (as you might have gathered).
|
6
|
+
The game is played on a field of cells, each of which has eight neighbors (adjacent cells).
|
7
|
+
A cell is either occupied (by an organism) or not.
|
8
|
+
The rules for deriving a generation from the previous one are these:
|
9
|
+
|
10
|
+
Death
|
11
|
+
-----
|
12
|
+
If an occupied cell has 0, 1, 4, 5, 6, 7, or 8 occupied neighbors, the organism dies
|
13
|
+
(0, 1: of loneliness; 4 thru 8: of overcrowding).
|
14
|
+
|
15
|
+
Survival
|
16
|
+
--------
|
17
|
+
If an occupied cell has two or three neighbors, the organism survives to the next generation.
|
18
|
+
|
19
|
+
Birth
|
20
|
+
-----
|
21
|
+
If an unoccupied cell has three occupied neighbors, it becomes occupied.
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'behaviour/examples/helper'
|
2
|
+
|
3
|
+
describe Grid do
|
4
|
+
it 'should be empty when created' do
|
5
|
+
# given
|
6
|
+
expected_contents = [
|
7
|
+
[0, 0, 0],
|
8
|
+
[0, 0, 0]
|
9
|
+
]
|
10
|
+
grid = Grid.new(2, 3)
|
11
|
+
|
12
|
+
# when
|
13
|
+
contents = grid.contents
|
14
|
+
|
15
|
+
# then
|
16
|
+
contents.should == expected_contents
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should compare equal based on its contents' do
|
20
|
+
# given
|
21
|
+
grid1 = Grid.new(2, 3)
|
22
|
+
grid2 = Grid.new(2, 3)
|
23
|
+
|
24
|
+
# then
|
25
|
+
grid1.should == grid2
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should be able to replace its contents' do
|
29
|
+
# given
|
30
|
+
grid = Grid.new(2,2)
|
31
|
+
new_contents = [[0,1,0], [1,0,1]]
|
32
|
+
|
33
|
+
# when
|
34
|
+
grid.contents = new_contents
|
35
|
+
|
36
|
+
# then
|
37
|
+
grid.contents.should == new_contents
|
38
|
+
grid.rows.should == 2
|
39
|
+
grid.columns.should == 3
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should add an organism' do
|
43
|
+
# given
|
44
|
+
grid = Grid.new(2, 2)
|
45
|
+
expected = Grid.new(2, 2)
|
46
|
+
expected.contents = [[1,0],[0,0]]
|
47
|
+
|
48
|
+
# when
|
49
|
+
grid.create_at(0,0)
|
50
|
+
|
51
|
+
# then
|
52
|
+
grid.should == expected
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should create itself from a string' do
|
56
|
+
# given
|
57
|
+
expected = Grid.new 3, 3
|
58
|
+
expected.create_at(0,0)
|
59
|
+
expected.create_at(1,0)
|
60
|
+
expected.create_at(2,2)
|
61
|
+
|
62
|
+
# when
|
63
|
+
actual = Grid.from_s "X.. X.. ..X"
|
64
|
+
|
65
|
+
# then
|
66
|
+
actual.should == expected
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Story: cells with less than two neighbours die
|
2
|
+
|
3
|
+
As a game producer
|
4
|
+
I want cells with less than two neighbours to die
|
5
|
+
So that I can illustrate how the game works to people with money
|
6
|
+
|
7
|
+
Scenario: cells with zero or one neighbour die
|
8
|
+
|
9
|
+
Given the grid looks like
|
10
|
+
........
|
11
|
+
.XX.XX..
|
12
|
+
.XX.....
|
13
|
+
....X...
|
14
|
+
........
|
15
|
+
When the next step occurs
|
16
|
+
Then the grid should look like
|
17
|
+
........
|
18
|
+
.XX.....
|
19
|
+
.XX.....
|
20
|
+
........
|
21
|
+
........
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Story: cells with more than three neighbours die
|
2
|
+
|
3
|
+
As a game producer
|
4
|
+
I want cells with more than three neighbours to die
|
5
|
+
So that I can show the people with money how we are getting on
|
6
|
+
|
7
|
+
Scenario: blink
|
8
|
+
|
9
|
+
Given the grid looks like
|
10
|
+
.....
|
11
|
+
...XX
|
12
|
+
...XX
|
13
|
+
.XX..
|
14
|
+
.XX..
|
15
|
+
When the next step occurs
|
16
|
+
Then the grid should look like
|
17
|
+
.....
|
18
|
+
...XX
|
19
|
+
....X
|
20
|
+
.X...
|
21
|
+
.XX..
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Story: Empty spaces with three neighbours create a cell
|
2
|
+
|
3
|
+
As a game producer
|
4
|
+
I want empty cells with three neighbours to die
|
5
|
+
So that I have a minimum feature set to ship
|
6
|
+
|
7
|
+
Scenario: the glider
|
8
|
+
|
9
|
+
Given the grid looks like
|
10
|
+
...X..
|
11
|
+
..X...
|
12
|
+
..XXX.
|
13
|
+
......
|
14
|
+
......
|
15
|
+
When the next step occurs
|
16
|
+
Then the grid should look like
|
17
|
+
......
|
18
|
+
..X.X.
|
19
|
+
..XX..
|
20
|
+
...X..
|
21
|
+
......
|
22
|
+
When the next step occurs
|
23
|
+
Then the grid should look like
|
24
|
+
......
|
25
|
+
..X...
|
26
|
+
..X.X.
|
27
|
+
..XX..
|
28
|
+
......
|
29
|
+
When the next step occurs
|
30
|
+
Then the grid should look like
|
31
|
+
......
|
32
|
+
...X..
|
33
|
+
.XX...
|
34
|
+
..XX..
|
35
|
+
......
|
36
|
+
When the next step occurs
|
37
|
+
Then the grid should look like
|
38
|
+
......
|
39
|
+
..X...
|
40
|
+
.X....
|
41
|
+
.XXX..
|
42
|
+
......
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Story: I can create a cell
|
2
|
+
|
3
|
+
As a game producer
|
4
|
+
I want to create a cell
|
5
|
+
So that I can show the grid to people
|
6
|
+
|
7
|
+
Scenario: nothing to see here
|
8
|
+
|
9
|
+
Given a 3 x 3 game
|
10
|
+
Then the grid should look like
|
11
|
+
...
|
12
|
+
...
|
13
|
+
...
|
14
|
+
|
15
|
+
Scenario: all on its lonesome
|
16
|
+
|
17
|
+
Given a 3 x 3 game
|
18
|
+
When I create a cell at 1, 1
|
19
|
+
Then the grid should look like
|
20
|
+
...
|
21
|
+
.X.
|
22
|
+
...
|
23
|
+
|
24
|
+
Scenario: some friends arrive
|
25
|
+
|
26
|
+
Given a 3 x 3 game
|
27
|
+
When I create a cell at 0, 0
|
28
|
+
and I create a cell at 0, 1
|
29
|
+
and I create a cell at 2, 2
|
30
|
+
Then the grid should look like
|
31
|
+
XX.
|
32
|
+
...
|
33
|
+
..X
|
34
|
+
|
35
|
+
Scenario: more cells more more
|
36
|
+
|
37
|
+
Given the grid has three cells
|
38
|
+
When I create a celll at 3, 1
|
39
|
+
Then the grid should look like
|
40
|
+
XX.
|
41
|
+
..X
|
42
|
+
..X
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Story: I can kill a cell
|
2
|
+
|
3
|
+
As a game producer
|
4
|
+
I want to kill a cell
|
5
|
+
So that when I make a mistake I dont have to start again
|
6
|
+
|
7
|
+
Scenario: bang youre dead
|
8
|
+
|
9
|
+
Given the grid looks like
|
10
|
+
XX.
|
11
|
+
.X.
|
12
|
+
..X
|
13
|
+
When I destroy the cell at 0, 1
|
14
|
+
Then the grid should look like
|
15
|
+
X..
|
16
|
+
.X.
|
17
|
+
..X
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Story: The grid wraps
|
2
|
+
|
3
|
+
As a game player
|
4
|
+
I want the grid to wrap
|
5
|
+
So that untidy stuff at the edges is avoided
|
6
|
+
|
7
|
+
Scenario: crowded in the corners
|
8
|
+
|
9
|
+
Given the grid looks like
|
10
|
+
X.X
|
11
|
+
...
|
12
|
+
X.X
|
13
|
+
When the next step is taken
|
14
|
+
Then the grid should look like
|
15
|
+
X.X
|
16
|
+
...
|
17
|
+
X.X
|
18
|
+
|
19
|
+
|
20
|
+
Scenario: the glider returns
|
21
|
+
|
22
|
+
Given the glider
|
23
|
+
......
|
24
|
+
..X...
|
25
|
+
.X....
|
26
|
+
.XXX..
|
27
|
+
......
|
28
|
+
When the next step is taken
|
29
|
+
and the next step is taken
|
30
|
+
and the next step is taken
|
31
|
+
and the next step is taken
|
32
|
+
Then the grid should look like
|
33
|
+
......
|
34
|
+
......
|
35
|
+
.X....
|
36
|
+
X.....
|
37
|
+
XXX...
|
38
|
+
When the next step is taken
|
39
|
+
Then the grid should look like
|
40
|
+
.X....
|
41
|
+
......
|
42
|
+
......
|
43
|
+
X.X...
|
44
|
+
XX....
|
45
|
+
When the next step is taken
|
46
|
+
Then the grid should look like
|
47
|
+
XX....
|
48
|
+
......
|
49
|
+
......
|
50
|
+
X.....
|
51
|
+
X.X...
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'rbehave'
|
4
|
+
|
5
|
+
require 'life'
|
6
|
+
|
7
|
+
Story "I can create a cell",
|
8
|
+
%(As a game producer
|
9
|
+
I want to create a cell
|
10
|
+
So that I can show the grid to people) do
|
11
|
+
|
12
|
+
Scenario "nothing to see here" do
|
13
|
+
Given "a game with dimensions", 3, 3 do |rows,cols|
|
14
|
+
@game = Game.new(rows,cols)
|
15
|
+
end
|
16
|
+
|
17
|
+
Then "the grid should look like", %(
|
18
|
+
...
|
19
|
+
...
|
20
|
+
...
|
21
|
+
) do |grid_str|
|
22
|
+
@game.grid.should == Grid.from_s(grid_str)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Scenario "all on its lonesome" do
|
27
|
+
Given "a game with dimensions", 2, 2
|
28
|
+
When "I create a cell at", 1, 1 do |row,col|
|
29
|
+
@game.grid.create_at(row,col)
|
30
|
+
end
|
31
|
+
Then "the grid should look like", %(
|
32
|
+
..
|
33
|
+
.X
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
Scenario "the grid has three cells" do
|
38
|
+
Given "a game with dimensions", 3, 3
|
39
|
+
When "I create a cell at", 0, 0
|
40
|
+
When "I create a cell at", 0, 1
|
41
|
+
When "I create a cell at", 2, 2
|
42
|
+
Then "the grid should look like", %(
|
43
|
+
XX.
|
44
|
+
...
|
45
|
+
..X
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
Scenario "more cells more more" do
|
50
|
+
GivenScenario "the grid has three cells"
|
51
|
+
When "I create a cell at", 2, 0
|
52
|
+
Then "the grid should look like", %(
|
53
|
+
XX.
|
54
|
+
...
|
55
|
+
X.X
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Story: Show the game field
|
2
|
+
As a game player
|
3
|
+
I want to see the field
|
4
|
+
so that I can observe the progress of the organisms
|
5
|
+
|
6
|
+
Scenario: an empty field
|
7
|
+
Given a new game starts
|
8
|
+
When the game displays the field
|
9
|
+
Then the field should be empty
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
StoryBuilder story = stories.createStory().called("a story")
|
16
|
+
.asA("person")
|
17
|
+
.iWant("to do something")
|
18
|
+
.soThat("I can rule the world");
|
19
|
+
story.addScenario().called("happy path").as()
|
20
|
+
.given("some context")
|
21
|
+
.when("some event happens")
|
22
|
+
.then("expect some outcome");
|