Class: RBehave::Runner::StoryRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rbehave/runner/story_runner.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario_runner, world_creator = World) ⇒ StoryRunner

Returns a new instance of StoryRunner.



18
19
20
21
22
23
24
25
26
# File 'lib/rbehave/runner/story_runner.rb', line 18

def initialize(scenario_runner, world_creator = World)
  StoryRunner.current_story_runner = self
  @scenario_runner = scenario_runner
  @world_creator = world_creator
  @stories = []
  @scenarios_by_story = {}
  @scenarios = []
  @listeners = []
end

Class Attribute Details

.current_story_runnerObject

Returns the value of attribute current_story_runner.



5
6
7
# File 'lib/rbehave/runner/story_runner.rb', line 5

def current_story_runner
  @current_story_runner
end

Instance Attribute Details

#current_storyObject

Returns the value of attribute current_story.



16
17
18
# File 'lib/rbehave/runner/story_runner.rb', line 16

def current_story
  @current_story
end

#scenariosObject

Returns the value of attribute scenarios.



16
17
18
# File 'lib/rbehave/runner/story_runner.rb', line 16

def scenarios
  @scenarios
end

#storiesObject

Returns the value of attribute stories.



16
17
18
# File 'lib/rbehave/runner/story_runner.rb', line 16

def stories
  @stories
end

Class Method Details

.current_storyObject



7
8
9
# File 'lib/rbehave/runner/story_runner.rb', line 7

def current_story
  current_story_runner.current_story
end

.scenario_from_current_story(scenario_name) ⇒ Object



11
12
13
# File 'lib/rbehave/runner/story_runner.rb', line 11

def scenario_from_current_story(scenario_name)
  current_story_runner.scenario_from_current_story(scenario_name)
end

Instance Method Details

#add_listener(listener) ⇒ Object



58
59
60
# File 'lib/rbehave/runner/story_runner.rb', line 58

def add_listener(listener)
  @listeners << listener
end

#run_storiesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rbehave/runner/story_runner.rb', line 39

def run_stories
  return if @stories.empty?
  @listeners.each { |l| l.run_started(scenarios.size) }
  @stories.each do |story|
    @current_story = story
    @listeners.each { |l| l.story_started(story.title, story.narrative) }
    scenarios = @scenarios_by_story[story.title]
    scenarios.each do |scenario|
      type = story[:type] || Object
      args = story[:args] || []
      world = @world_creator.create(type, *args)
      world.instance_variable_set :@current_story, story
      @scenario_runner.run(scenario, world)
    end
    @listeners.each { |l| l.story_ended(story.title, story.narrative) }
  end
  @listeners.each { |l| l.run_ended }
end

#scenario_from_current_story(scenario_name) ⇒ Object



62
63
64
# File 'lib/rbehave/runner/story_runner.rb', line 62

def scenario_from_current_story(scenario_name)
  @scenarios_by_story[@current_story.title].find {|s| s.name == scenario_name }
end

#Story(title, narrative, params = {}, &body) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/rbehave/runner/story_runner.rb', line 28

def Story(title, narrative, params = {}, &body)
  story = Story.new(title, narrative, params, &body)
  @stories << story
  
  # collect scenarios
  collector = ScenarioCollector.new(story)
  story.run_in(collector)
  @scenarios += collector.scenarios
  @scenarios_by_story[story.title] = collector.scenarios
end