changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/story/extensions/main.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module Spec
2 module Story
3 module Extensions
4 module Main
5 def Story(title, narrative, params = {}, &body)
6 ::Spec::Story::Runner.story_runner.Story(title, narrative, params, &body)
7 end
8
9 # Calling this deprecated is silly, since it hasn't been released yet. But, for
10 # those who are reading this - this will be deleted before the 1.1 release.
11 def run_story(*args, &block)
12 runner = Spec::Story::Runner::PlainTextStoryRunner.new(*args)
13 runner.instance_eval(&block) if block
14 runner.run
15 end
16
17 # Creates (or appends to an existing) a namespaced group of steps for use in Stories
18 #
19 # == Examples
20 #
21 # # Creating a new group
22 # steps_for :forms do
23 # When("user enters $value in the $field field") do ... end
24 # When("user submits the $form form") do ... end
25 # end
26 def steps_for(tag, &block)
27 steps = rspec_story_steps[tag]
28 steps.instance_eval(&block) if block
29 steps
30 end
31
32 # Creates a context for running a Plain Text Story with specific groups of Steps.
33 # Also supports adding arbitrary steps that will only be accessible to
34 # the Story being run.
35 #
36 # == Examples
37 #
38 # # Run a Story with one group of steps
39 # with_steps_for :checking_accounts do
40 # run File.dirname(__FILE__) + "/withdraw_cash"
41 # end
42 #
43 # # Run a Story, adding steps that are only available for this Story
44 # with_steps_for :accounts do
45 # Given "user is logged in as account administrator"
46 # run File.dirname(__FILE__) + "/reconcile_accounts"
47 # end
48 #
49 # # Run a Story with steps from two groups
50 # with_steps_for :checking_accounts, :savings_accounts do
51 # run File.dirname(__FILE__) + "/transfer_money"
52 # end
53 #
54 # # Run a Story with a specific Story extension
55 # with_steps_for :login, :navigation do
56 # run File.dirname(__FILE__) + "/user_changes_password", :type => RailsStory
57 # end
58 def with_steps_for(*tags, &block)
59 steps = Spec::Story::StepGroup.new do
60 extend StoryRunnerStepGroupAdapter
61 end
62 tags.each {|tag| steps << rspec_story_steps[tag]}
63 steps.instance_eval(&block) if block
64 steps
65 end
66
67 private
68
69 module StoryRunnerStepGroupAdapter
70 def run(path, options={})
71 runner = Spec::Story::Runner::PlainTextStoryRunner.new(path, options)
72 runner.steps << self
73 runner.run
74 end
75 end
76
77 def rspec_story_steps # :nodoc:
78 $rspec_story_steps ||= Spec::Story::StepGroupHash.new
79 end
80
81 end
82 end
83 end
84end
85
86include Spec::Story::Extensions::Main