rbehave 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -0
- data/behaviour/examples/rbehave/world_behaviour.rb +10 -0
- data/examples/game-of-life/behaviour/everything.rb +2 -2
- data/examples/game-of-life/behaviour/examples/game_behaviour.rb +25 -1
- data/examples/game-of-life/behaviour/stories/create_a_cell.rb +1 -2
- data/examples/game-of-life/behaviour/stories/kill_a_cell.rb +27 -0
- data/examples/game-of-life/behaviour/stories/stories.rb +2 -0
- data/examples/game-of-life/life/game.rb +17 -0
- data/examples/game-of-life/life/grid.rb +5 -1
- data/lib/rbehave/simple_step.rb +4 -10
- data/lib/rbehave/version.rb +3 -3
- data/lib/rbehave/world.rb +6 -2
- metadata +14 -4
data/Manifest.txt
CHANGED
@@ -40,11 +40,13 @@ examples/game-of-life/behaviour/everything.rb
|
|
40
40
|
examples/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story
|
41
41
|
examples/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story
|
42
42
|
examples/game-of-life/behaviour/stories/TheGridWraps.story
|
43
|
+
examples/game-of-life/behaviour/stories/stories.rb
|
43
44
|
examples/game-of-life/behaviour/stories/stories.txt
|
44
45
|
examples/game-of-life/behaviour/stories/ICanKillACell.story
|
45
46
|
examples/game-of-life/behaviour/stories/ICanCreateACell.story
|
46
47
|
examples/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
|
47
48
|
examples/game-of-life/behaviour/stories/create_a_cell.rb
|
49
|
+
examples/game-of-life/behaviour/stories/kill_a_cell.rb
|
48
50
|
examples/game-of-life/behaviour/examples/examples.rb
|
49
51
|
examples/game-of-life/behaviour/examples/grid_behaviour.rb
|
50
52
|
examples/game-of-life/behaviour/examples/game_behaviour.rb
|
@@ -320,5 +320,15 @@ module RBehave
|
|
320
320
|
verify_mocks
|
321
321
|
$scenario_ran.should == true
|
322
322
|
end
|
323
|
+
|
324
|
+
it 'should include rspec matchers' do
|
325
|
+
# given
|
326
|
+
world = World.create
|
327
|
+
|
328
|
+
# then
|
329
|
+
world.instance_eval do
|
330
|
+
'hello'.should match(/^hello$/)
|
331
|
+
end
|
332
|
+
end
|
323
333
|
end
|
324
334
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'behaviour/examples/examples
|
2
|
-
require 'behaviour/stories/stories
|
1
|
+
require 'behaviour/examples/examples'
|
2
|
+
require 'behaviour/stories/stories'
|
@@ -11,4 +11,28 @@ describe Game do
|
|
11
11
|
# then
|
12
12
|
game.grid.should be_kind_of(Grid)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
it 'should create a cell' do
|
16
|
+
# given
|
17
|
+
game = Game.new(2, 2)
|
18
|
+
expected_grid = Grid.from_string( 'X. ..' )
|
19
|
+
|
20
|
+
# when
|
21
|
+
game.create_at(0, 0)
|
22
|
+
|
23
|
+
# then
|
24
|
+
game.grid.should == expected_grid
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should destroy a cell' do
|
28
|
+
# given
|
29
|
+
game = Game.new(2,2)
|
30
|
+
game.grid = Grid.from_string('X. ..')
|
31
|
+
|
32
|
+
# when
|
33
|
+
game.destroy_at(0,0)
|
34
|
+
|
35
|
+
# then
|
36
|
+
game.grid.should == Grid.from_string('.. ..')
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'spec'
|
3
2
|
require 'rbehave'
|
4
3
|
|
5
4
|
require 'life'
|
@@ -26,7 +25,7 @@ Story "I can create a cell",
|
|
26
25
|
Scenario "all on its lonesome" do
|
27
26
|
Given "a game with dimensions", 2, 2
|
28
27
|
When "I create a cell at", 1, 1 do |row,col|
|
29
|
-
@game.
|
28
|
+
@game.create_at(row,col)
|
30
29
|
end
|
31
30
|
Then "the grid should look like", %(
|
32
31
|
..
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbehave'
|
3
|
+
|
4
|
+
Story 'I can kill a cell',
|
5
|
+
%(As a game producer
|
6
|
+
I want to kill a cell
|
7
|
+
So that when I make a mistake I dont have to start again) do
|
8
|
+
|
9
|
+
Scenario 'bang youre dead' do
|
10
|
+
|
11
|
+
Given 'a game that looks like', %(
|
12
|
+
XX.
|
13
|
+
.X.
|
14
|
+
..X
|
15
|
+
) do |dots|
|
16
|
+
@game = Game.from_string dots
|
17
|
+
end
|
18
|
+
When 'I destroy the cell at', 0, 1 do |row,col|
|
19
|
+
@game.destroy_at(row,col)
|
20
|
+
end
|
21
|
+
Then 'the grid should look like', %(
|
22
|
+
X..
|
23
|
+
.X.
|
24
|
+
..X
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -3,4 +3,21 @@ class Game
|
|
3
3
|
def initialize(rows,cols)
|
4
4
|
@grid = Grid.new(rows, cols)
|
5
5
|
end
|
6
|
+
|
7
|
+
def create_at(row,col)
|
8
|
+
@grid.create_at(row,col)
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy_at(row,col)
|
12
|
+
@grid.destroy_at(row, col)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_string(dots)
|
16
|
+
grid = Grid.from_string(dots)
|
17
|
+
game = Game.new(grid.rows, grid.columns)
|
18
|
+
game.instance_eval do
|
19
|
+
@grid = grid
|
20
|
+
end
|
21
|
+
return game
|
22
|
+
end
|
6
23
|
end
|
@@ -23,8 +23,12 @@ class Grid
|
|
23
23
|
@contents[row][col] = 1
|
24
24
|
end
|
25
25
|
|
26
|
+
def destroy_at(row,col)
|
27
|
+
@contents[row][col] = 0
|
28
|
+
end
|
29
|
+
|
26
30
|
def self.from_string(str)
|
27
|
-
row_strings = str.split
|
31
|
+
row_strings = str.split(' ')
|
28
32
|
grid = Grid.new(row_strings.size, row_strings[0].size)
|
29
33
|
|
30
34
|
row_strings.each_with_index do |row, row_index|
|
data/lib/rbehave/simple_step.rb
CHANGED
@@ -2,20 +2,14 @@ module RBehave
|
|
2
2
|
class SimpleStep
|
3
3
|
def initialize(name, &block)
|
4
4
|
@name = name
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
@mod = Module.new do
|
6
|
+
define_method name, &block
|
7
|
+
end
|
8
8
|
end
|
9
9
|
|
10
10
|
def perform(instance, *args)
|
11
11
|
instance.extend(@mod)
|
12
12
|
instance.__send__(@name, *args)
|
13
|
-
# block = @block
|
14
|
-
# instance.instance_eval do
|
15
|
-
# puts __id__ if $debug
|
16
|
-
# block.call(*args)
|
17
|
-
# end
|
18
13
|
end
|
19
|
-
|
20
14
|
end
|
21
|
-
end
|
15
|
+
end
|
data/lib/rbehave/version.rb
CHANGED
data/lib/rbehave/world.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/expectations'
|
3
|
+
require 'spec/matchers'
|
4
|
+
|
1
5
|
module RBehave
|
2
6
|
=begin
|
3
7
|
A World represents the actual instance a scenario will run in.
|
@@ -8,6 +12,7 @@ module RBehave
|
|
8
12
|
blocks.
|
9
13
|
=end
|
10
14
|
module World
|
15
|
+
include Spec::Matchers
|
11
16
|
# store steps and listeners in the singleton metaclass.
|
12
17
|
# This serves both to keep them out of the way of runtime Worlds
|
13
18
|
# and to make them available to all instances.
|
@@ -52,8 +57,7 @@ module RBehave
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def GivenScenario(name)
|
55
|
-
World.run_with_suspended_listeners(
|
56
|
-
self, :'given scenario', name, GivenScenario.new(name))
|
60
|
+
World.run_with_suspended_listeners(self, :'given scenario', name, GivenScenario.new(name))
|
57
61
|
end
|
58
62
|
|
59
63
|
def Given(name, *args, &block)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbehave
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-06-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2007-06-25 00:00:00 +01:00
|
8
8
|
summary: RBehave
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -71,11 +71,13 @@ files:
|
|
71
71
|
- examples/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story
|
72
72
|
- examples/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story
|
73
73
|
- examples/game-of-life/behaviour/stories/TheGridWraps.story
|
74
|
+
- examples/game-of-life/behaviour/stories/stories.rb
|
74
75
|
- examples/game-of-life/behaviour/stories/stories.txt
|
75
76
|
- examples/game-of-life/behaviour/stories/ICanKillACell.story
|
76
77
|
- examples/game-of-life/behaviour/stories/ICanCreateACell.story
|
77
78
|
- examples/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
|
78
79
|
- examples/game-of-life/behaviour/stories/create_a_cell.rb
|
80
|
+
- examples/game-of-life/behaviour/stories/kill_a_cell.rb
|
79
81
|
- examples/game-of-life/behaviour/examples/examples.rb
|
80
82
|
- examples/game-of-life/behaviour/examples/grid_behaviour.rb
|
81
83
|
- examples/game-of-life/behaviour/examples/game_behaviour.rb
|
@@ -101,5 +103,13 @@ extensions: []
|
|
101
103
|
|
102
104
|
requirements: []
|
103
105
|
|
104
|
-
dependencies:
|
105
|
-
|
106
|
+
dependencies:
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: rspec
|
109
|
+
version_requirement:
|
110
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.0.1
|
115
|
+
version:
|