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.
Files changed (47) hide show
  1. data/CHANGELOG.txt +5 -0
  2. data/Manifest.txt +44 -17
  3. data/NOTES.txt +2 -7
  4. data/behaviour/everything.rb +1 -1
  5. data/behaviour/examples/{everything.rb → examples.rb} +0 -0
  6. data/behaviour/examples/rbehave/documenter/plain_text_documenter_behaviour.rb +1 -0
  7. data/behaviour/examples/rbehave/given_scenario_behaviour.rb +26 -0
  8. data/behaviour/examples/rbehave/runner/options_behaviour.rb +39 -0
  9. data/behaviour/examples/rbehave/runner/runner_behaviour.rb +39 -0
  10. data/behaviour/examples/rbehave/runner/story_runner_behaviour.rb +58 -2
  11. data/behaviour/examples/rbehave/simple_step_behaviour.rb +35 -0
  12. data/behaviour/examples/rbehave/step_mother_behaviour.rb +32 -0
  13. data/behaviour/examples/rbehave/world_behaviour.rb +44 -5
  14. data/behaviour/examples/rspec_adapter.rb +3 -1
  15. data/examples/game-of-life/.loadpath +5 -0
  16. data/examples/game-of-life/.project +18 -0
  17. data/examples/game-of-life/README.txt +21 -0
  18. data/examples/game-of-life/behaviour/everything.rb +2 -0
  19. data/examples/game-of-life/behaviour/examples/examples.rb +2 -0
  20. data/examples/game-of-life/behaviour/examples/game_behaviour.rb +17 -0
  21. data/examples/game-of-life/behaviour/examples/grid_behaviour.rb +68 -0
  22. data/examples/game-of-life/behaviour/examples/helper.rb +2 -0
  23. data/examples/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +21 -0
  24. data/examples/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +21 -0
  25. data/examples/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +42 -0
  26. data/examples/game-of-life/behaviour/stories/ICanCreateACell.story +42 -0
  27. data/examples/game-of-life/behaviour/stories/ICanKillACell.story +17 -0
  28. data/examples/game-of-life/behaviour/stories/TheGridWraps.story +53 -0
  29. data/examples/game-of-life/behaviour/stories/create_a_cell.rb +58 -0
  30. data/examples/game-of-life/behaviour/stories/stories.txt +22 -0
  31. data/examples/game-of-life/life.rb +2 -0
  32. data/examples/game-of-life/life/game.rb +6 -0
  33. data/examples/game-of-life/life/grid.rb +38 -0
  34. data/lib/rbehave.rb +6 -71
  35. data/lib/rbehave/documenter/plain_text_documenter.rb +2 -2
  36. data/lib/rbehave/exceptions.rb +3 -3
  37. data/lib/rbehave/given_scenario.rb +12 -0
  38. data/lib/rbehave/runner.rb +52 -0
  39. data/lib/rbehave/runner/options.rb +26 -0
  40. data/lib/rbehave/runner/story_runner.rb +26 -5
  41. data/lib/rbehave/simple_step.rb +14 -0
  42. data/lib/rbehave/step_mother.rb +19 -0
  43. data/lib/rbehave/story.rb +8 -3
  44. data/lib/rbehave/version.rb +1 -1
  45. data/lib/rbehave/world.rb +31 -23
  46. metadata +47 -19
  47. data/Rakefile +0 -54
data/CHANGELOG.txt CHANGED
@@ -1,2 +1,7 @@
1
+ == Version 0.2.0
2
+ * Steps can take parameters
3
+ * Added GivenScenario
4
+ * Added proper command-line args
5
+
1
6
  == Version 0.1.0
2
7
  * First running version
data/Manifest.txt CHANGED
@@ -1,31 +1,58 @@
1
- lib/rbehave/reporter/plain_text_reporter.rb
1
+ lib/rbehave.rb
2
+ lib/rbehave/version.rb
3
+ lib/rbehave/runner/scenario_runner.rb
4
+ lib/rbehave/runner/story_runner.rb
5
+ lib/rbehave/runner/options.rb
6
+ lib/rbehave/runner/scenario_collector.rb
2
7
  lib/rbehave/exceptions.rb
8
+ lib/rbehave/given_scenario.rb
9
+ lib/rbehave/runner.rb
10
+ lib/rbehave/scenario.rb
11
+ lib/rbehave/step_mother.rb
12
+ lib/rbehave/reporter/plain_text_reporter.rb
13
+ lib/rbehave/simple_step.rb
3
14
  lib/rbehave/documenter/plain_text_documenter.rb
4
15
  lib/rbehave/world.rb
5
- lib/rbehave/runner/story_runner.rb
6
- lib/rbehave/runner/scenario_collector.rb
7
- lib/rbehave/runner/scenario_runner.rb
8
16
  lib/rbehave/story.rb
9
- lib/rbehave/version.rb
10
- lib/rbehave/scenario.rb
11
- lib/rbehave.rb
12
17
  behaviour/everything.rb
13
- behaviour/examples/rbehave/reporter/plain_text_reporter_behaviour.rb
14
- behaviour/examples/rbehave/world_behaviour.rb
15
- behaviour/examples/rbehave/documenter/plain_text_documenter_behaviour.rb
16
- behaviour/examples/rbehave/story_behaviour.rb
17
- behaviour/examples/rbehave/runner/scenario_runner_behaviour.rb
18
+ behaviour/examples/examples.rb
19
+ behaviour/examples/rspec_adapter.rb
20
+ behaviour/examples/helper.rb
18
21
  behaviour/examples/rbehave/runner/story_runner_behaviour.rb
22
+ behaviour/examples/rbehave/runner/runner_behaviour.rb
23
+ behaviour/examples/rbehave/runner/scenario_runner_behaviour.rb
24
+ behaviour/examples/rbehave/runner/options_behaviour.rb
19
25
  behaviour/examples/rbehave/runner/scenario_collector_behaviour.rb
26
+ behaviour/examples/rbehave/world_behaviour.rb
20
27
  behaviour/examples/rbehave/exception_behaviour.rb
21
- behaviour/examples/rspec_adapter.rb
22
- behaviour/examples/everything.rb
23
- behaviour/examples/helper.rb
24
-
28
+ behaviour/examples/rbehave/story_behaviour.rb
29
+ behaviour/examples/rbehave/given_scenario_behaviour.rb
30
+ behaviour/examples/rbehave/reporter/plain_text_reporter_behaviour.rb
31
+ behaviour/examples/rbehave/step_mother_behaviour.rb
32
+ behaviour/examples/rbehave/documenter/plain_text_documenter_behaviour.rb
33
+ behaviour/examples/rbehave/simple_step_behaviour.rb
34
+ examples/game-of-life/life/game.rb
35
+ examples/game-of-life/life/grid.rb
36
+ examples/game-of-life/.loadpath
37
+ examples/game-of-life/behaviour/everything.rb
38
+ examples/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story
39
+ examples/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story
40
+ examples/game-of-life/behaviour/stories/TheGridWraps.story
41
+ examples/game-of-life/behaviour/stories/stories.txt
42
+ examples/game-of-life/behaviour/stories/ICanKillACell.story
43
+ examples/game-of-life/behaviour/stories/ICanCreateACell.story
44
+ examples/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
45
+ examples/game-of-life/behaviour/stories/create_a_cell.rb
46
+ examples/game-of-life/behaviour/examples/examples.rb
47
+ examples/game-of-life/behaviour/examples/grid_behaviour.rb
48
+ examples/game-of-life/behaviour/examples/game_behaviour.rb
49
+ examples/game-of-life/behaviour/examples/helper.rb
50
+ examples/game-of-life/.project
51
+ examples/game-of-life/life.rb
52
+ examples/game-of-life/README.txt
25
53
  CHANGELOG.txt
26
54
  History.txt
27
55
  Manifest.txt
28
56
  NOTES.txt
29
- Rakefile
30
57
  README.txt
31
58
  setup.rb
data/NOTES.txt CHANGED
@@ -1,11 +1,6 @@
1
- StoryRunner
2
- * should collect all the stories
3
- * should count all the scenarios in the stories
4
- * should execute the scenarios
5
-
6
- ScenarioRunner
7
- - should run scenarios in a World
1
+ - Run a single story - define steps outside of a scenario.
8
2
 
9
3
  Additions for rspec:
10
4
  pending(msg)
11
5
 
6
+ # :1,$!find lib behaviour examples *.txt setup.rb -type f | grep -v svn
@@ -1 +1 @@
1
- require 'behaviour/examples/everything'
1
+ require 'behaviour/examples/examples'
File without changes
@@ -1,4 +1,5 @@
1
1
  require 'behaviour/examples/helper'
2
+ require 'lib/rbehave/documenter/plain_text_documenter'
2
3
 
3
4
  module RBehave
4
5
  module Documenter
@@ -0,0 +1,26 @@
1
+ require 'behaviour/examples/helper'
2
+
3
+ module RBehave
4
+ describe GivenScenario do
5
+ it 'should execute a scenario from the current story in its world' do
6
+ # given
7
+ class MyWorld
8
+ attr :scenario_ran
9
+ end
10
+ instance = MyWorld.new
11
+ story = Story.new 'title', 'narrative' do end
12
+ scenario = Scenario.new story, 'scenario name' do
13
+ @scenario_ran = true
14
+ end
15
+ Runner::StoryRunner.expects(:scenario_from_current_story).with('scenario name').returns(scenario)
16
+
17
+ step = GivenScenario.new 'scenario name'
18
+
19
+ # when
20
+ step.perform(instance)
21
+
22
+ # then
23
+ ensure_that instance.scenario_ran, is(true)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ require 'behaviour/examples/helper'
2
+
3
+ module RBehave
4
+ module Runner
5
+ describe Options do
6
+ setup do
7
+ @options = Options.new
8
+ end
9
+
10
+ it 'should parse -n as dry run' do
11
+ # when
12
+ @options.parse %w[ -n ]
13
+ # then
14
+ ensure_that @options.dry_run, is(true)
15
+ end
16
+
17
+ it 'should parse --dry-run as dry run' do
18
+ # when
19
+ @options.parse %w[ --dry-run ]
20
+ # then
21
+ ensure_that @options.dry_run, is(true)
22
+ end
23
+
24
+ it 'should parse "-f fmt as format' do
25
+ # when
26
+ @options.parse %w[ -f s ]
27
+ # then
28
+ ensure_that @options.format, is(:simple)
29
+ end
30
+
31
+ it 'should parse "--format fmt as format' do
32
+ # when
33
+ @options.parse %w[ --format h ]
34
+ # then
35
+ ensure_that @options.format, is(:html)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require 'behaviour/examples/helper'
2
+
3
+ module RBehave
4
+ describe Runner do
5
+ def dev_null
6
+ io = $stdout.dup
7
+ def io.write(str)
8
+ str.to_s.size
9
+ end
10
+ return io
11
+ end
12
+
13
+ setup do
14
+ @stdout, $stdout = $stdout, dev_null
15
+ @argv = Array.new(ARGV)
16
+ end
17
+
18
+ teardown do
19
+ $stdout = @stdout
20
+ ARGV.clear; ARGV << @argv
21
+ end
22
+
23
+ it 'should wire up a singleton StoryRunner' do
24
+ Runner::story_runner.should_not be_nil
25
+ end
26
+
27
+ it 'should set its options based on ARGV' do
28
+ # given
29
+ Runner.module_eval { @options = nil }
30
+ ARGV << '--dry-run'
31
+
32
+ # when
33
+ options = Runner.options
34
+
35
+ # then
36
+ ensure_that options.dry_run, is(true)
37
+ end
38
+ end
39
+ end
@@ -42,7 +42,7 @@ module RBehave
42
42
  end
43
43
 
44
44
  # captures worlds passed into a ScenarioRunner
45
- class ScenarioRunnerThatStoresWorlds
45
+ class ScenarioWorldCatcher
46
46
  attr_accessor :worlds
47
47
  def run(scenario, world)
48
48
  (@worlds ||= []) << world
@@ -51,7 +51,7 @@ module RBehave
51
51
 
52
52
  it 'should run each scenario in a separate object' do
53
53
  # given
54
- scenario_world_catcher = ScenarioRunnerThatStoresWorlds.new
54
+ scenario_world_catcher = ScenarioWorldCatcher.new
55
55
  story_runner = StoryRunner.new(scenario_world_catcher)
56
56
  story_runner.Story 'story', 'narrative' do
57
57
  Scenario 'scenario1' do end
@@ -164,6 +164,62 @@ module RBehave
164
164
  # then
165
165
  verify_mocks
166
166
  end
167
+
168
+ it 'should run a story in an instance of a specified class' do
169
+ # given
170
+ scenario_world_catcher = ScenarioWorldCatcher.new
171
+ story_runner = StoryRunner.new(scenario_world_catcher)
172
+ story_runner.Story 'title', 'narrative', :type => String do
173
+ Scenario 'scenario' do end
174
+ end
175
+
176
+ # when
177
+ story_runner.run_stories
178
+
179
+ # then
180
+ scenario_world_catcher.worlds[0].should be_kind_of(String)
181
+ scenario_world_catcher.worlds[0].should be_kind_of(World)
182
+ end
183
+
184
+ it 'should pass initialization params through to the constructed instance' do
185
+ # given
186
+ scenario_world_catcher = ScenarioWorldCatcher.new
187
+ story_runner = StoryRunner.new(scenario_world_catcher)
188
+ story_runner.Story 'title', 'narrative', :type => Array, :args => [3] do
189
+ Scenario 'scenario' do end
190
+ end
191
+
192
+ # when
193
+ story_runner.run_stories
194
+
195
+ # then
196
+ scenario_world_catcher.worlds[0].should be_kind_of(Array)
197
+ scenario_world_catcher.worlds[0].size.should == 3
198
+ end
199
+
200
+ it 'should store the current running story' do
201
+ # given
202
+ $stories = []
203
+ story_runner = StoryRunner.new(ScenarioRunner.new)
204
+ story_runner.Story 'title1', 'narrative1' do
205
+ Scenario 'scenario1' do
206
+ $stories << StoryRunner.current_story
207
+ end
208
+ end
209
+ story_runner.Story 'title2', 'narrative2' do
210
+ Scenario 'scenario2' do
211
+ $stories << StoryRunner.current_story
212
+ end
213
+ end
214
+
215
+ # when
216
+ story_runner.run_stories
217
+
218
+ # then
219
+ $stories.size.should == 2
220
+ ensure_that $stories[0].title, is('title1')
221
+ ensure_that $stories[1].title, is('title2')
222
+ end
167
223
  end
168
224
  end
169
225
  end
@@ -0,0 +1,35 @@
1
+ require 'behaviour/examples/helper'
2
+
3
+ module RBehave
4
+ describe SimpleStep do
5
+ it 'should perform itself on an object' do
6
+ # given
7
+ $instance = nil
8
+ step = SimpleStep.new 'step' do
9
+ $instance = self
10
+ end
11
+ instance = Object.new
12
+
13
+ # when
14
+ step.perform(instance)
15
+
16
+ # then
17
+ $instance.should == instance
18
+ end
19
+
20
+ it 'should perform itself with parameters' do
21
+ # given
22
+ $result = nil
23
+ step = SimpleStep.new 'step' do |value|
24
+ $result = value
25
+ end
26
+ instance = Object.new
27
+
28
+ # when
29
+ step.perform(instance, 3)
30
+
31
+ # then
32
+ $result.should == 3
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require 'behaviour/examples/helper'
2
+
3
+ module RBehave
4
+ describe StepMother do
5
+ it 'should store a step by name and type' do
6
+ # given
7
+ step_mother = StepMother.new
8
+ step = SimpleStep.new("a given", &lambda {})
9
+ step_mother.store(:given, "a given", step)
10
+
11
+ # when
12
+ found = step_mother.find(:given, "a given")
13
+
14
+ # then
15
+ found.should == step
16
+ end
17
+
18
+ it 'should raise an error if a step is missing' do
19
+ # given
20
+ step_mother = StepMother.new
21
+
22
+ # when
23
+ ex = exception_from do
24
+ step_mother.find(:given, "doesn't exist")
25
+ end
26
+
27
+ # then
28
+ ensure_that ex, is_an(UnknownStepException)
29
+ ensure_that ex.message, is("doesn't exist")
30
+ end
31
+ end
32
+ end
@@ -29,6 +29,25 @@ module RBehave
29
29
  obj.should be_kind_of(World)
30
30
  end
31
31
 
32
+ it 'should pass arguments to #new when creating an object of a specified type that mixes in a world' do
33
+ # given
34
+ class Thing
35
+ attr_reader :name, :age
36
+ def initialize(name, age)
37
+ @name, @age = name, age
38
+ end
39
+ end
40
+
41
+ # when
42
+ obj = World::create Thing, "David", "I'm not telling"
43
+
44
+ # then
45
+ obj.should be_an_instance_of(Thing)
46
+ obj.name.should == "David"
47
+ obj.age.should == "I'm not telling"
48
+ obj.should be_kind_of(World)
49
+ end
50
+
32
51
  def ensure_world_executes_step(&block)
33
52
  # given
34
53
  obj = World::create
@@ -148,13 +167,13 @@ module RBehave
148
167
  ensure_that $second, is('first')
149
168
  end
150
169
 
151
- it 'should invoke the reused step in the new object instance' do
170
+ it 'should invoke a reused step in the new object instance' do
152
171
  # given
153
172
  $instances = []
154
173
  world1 = World.create
155
174
  world1.instance_eval do
156
175
  Given 'a given' do
157
- $instances << self
176
+ $instances << self.__id__
158
177
  end
159
178
  end
160
179
  world2 = World.create
@@ -163,12 +182,12 @@ module RBehave
163
182
  world2.instance_eval do
164
183
  Given 'a given' # reused
165
184
  Then 'an outcome' do
166
- $instances << self
185
+ $instances << self.__id__
167
186
  end
168
187
  end
169
188
 
170
189
  # then
171
- $instances.should == [ world1, world2, world2 ]
190
+ $instances.should == [ world1.__id__, world2.__id__, world2.__id__ ]
172
191
  end
173
192
 
174
193
  def ensure_world_propagates_error(expected_error, &block)
@@ -233,7 +252,7 @@ module RBehave
233
252
  verify_mocks
234
253
  end
235
254
 
236
- it 'should tell listeners but not execute the step if it is in dry-run mode' do
255
+ it 'should tell listeners but not execute the step in dry-run mode' do
237
256
  # given
238
257
  RBehave::Runner.dry_run = true
239
258
  mock_listener = mock('listener')
@@ -255,5 +274,25 @@ module RBehave
255
274
  verify_mocks
256
275
  $step_invoked.should be(false)
257
276
  end
277
+
278
+ it 'should ignore pending() calls in dry-run mode' do
279
+ begin
280
+ # given
281
+ world = World.create
282
+ RBehave::Runner::dry_run = true
283
+
284
+ # when
285
+ ex = exception_from do
286
+ world.instance_eval do
287
+ pending 'todo'
288
+ end
289
+ end
290
+
291
+ # then
292
+ ex.should be_nil
293
+ ensure
294
+ RBehave::Runner::dry_run = false
295
+ end
296
+ end
258
297
  end
259
298
  end