Class: Spec::Story::Runner::StoryRunner

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

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.



19
20
21
22
23
24
25
26
27
# File 'lib/spec/story/runner/story_runner.rb', line 19

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

Instance Attribute Details

#current_storyObject

Returns the value of attribute current_story.



17
18
19
# File 'lib/spec/story/runner/story_runner.rb', line 17

def current_story
  @current_story
end

#scenariosObject

Returns the value of attribute scenarios.



17
18
19
# File 'lib/spec/story/runner/story_runner.rb', line 17

def scenarios
  @scenarios
end

#storiesObject

Returns the value of attribute stories.



17
18
19
# File 'lib/spec/story/runner/story_runner.rb', line 17

def stories
  @stories
end

Class Method Details

.current_story_runnerObject



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

def self.current_story_runner
  @current_story_runner
end

.current_story_runner=(current_story_runner) ⇒ Object



9
10
11
# File 'lib/spec/story/runner/story_runner.rb', line 9

def self.current_story_runner=(current_story_runner)
  @current_story_runner = current_story_runner
end

.scenario_from_current_story(scenario_name) ⇒ Object



13
14
15
# File 'lib/spec/story/runner/story_runner.rb', line 13

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

Instance Method Details

#add_listener(listener) ⇒ Object



64
65
66
# File 'lib/spec/story/runner/story_runner.rb', line 64

def add_listener(listener)
  @listeners << listener
end

#run_storiesObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spec/story/runner/story_runner.rb', line 40

def run_stories
  return if @stories.empty?
  @listeners.each { |l| l.run_started(scenarios.size) }
  success = true
  @stories.each do |story|
    story.assign_steps_to(World)
    @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)
      success = success & @scenario_runner.run(scenario, world)
    end
    @listeners.each { |l| l.story_ended(story.title, story.narrative) }
    World.step_mother.clear
  end
  unique_steps = (World.step_names.collect {|n| Regexp === n ? n.source : n.to_s}).uniq.sort
  @listeners.each { |l| l.collected_steps(unique_steps) }
  @listeners.each { |l| l.run_ended }
  return success
end

#scenario_from_current_story(scenario_name) ⇒ Object



68
69
70
# File 'lib/spec/story/runner/story_runner.rb', line 68

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



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

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