Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / lib / spec / story / runner / plain_text_story_runner.rb
blob34e5b015dfa4b73c173e0a57d2239165cdbea528
1 module Spec
2   module Story
3     module Runner
4       class PlainTextStoryRunner
5         # You can initialize a PlainTextStoryRunner with the path to the
6         # story file or a block, in which you can define the path using load.
7         #
8         # == Examples
9         #   
10         #   PlainTextStoryRunner.new('path/to/file')
11         #
12         #   PlainTextStoryRunner.new do |runner|
13         #     runner.load 'path/to/file'
14         #   end
15         def initialize(*args)
16           @options = Hash === args.last ? args.pop : {}
17           @story_file = args.empty? ? nil : args.shift
18           yield self if block_given?
19         end
20         
21         def []=(key, value)
22           @options[key] = value
23         end
24         
25         def load(path)
26           @story_file = path
27         end
28         
29         def run
30           raise "You must set a path to the file with the story. See the RDoc." if @story_file.nil?
31           mediator = Spec::Story::Runner::StoryMediator.new steps, Spec::Story::Runner.story_runner, @options
32           parser = Spec::Story::Runner::StoryParser.new mediator
34           story_text = File.read(@story_file)          
35           parser.parse(story_text.split("\n"))
37           mediator.run_stories
38         end
39         
40         def steps
41           @step_group ||= Spec::Story::StepGroup.new
42           yield @step_group if block_given?
43           @step_group
44         end
45       end
46     end
47   end
48 end