4 class StepGroupHash < Hash
7 h[k] = Spec::Story::StepGroup.new
13 def self.steps(&block)
14 @step_group ||= StepGroup.new(false)
15 @step_group.instance_eval(&block) if block
19 def initialize(init_defaults=true, &block)
20 @hash_of_lists_of_steps = Hash.new {|h, k| h[k] = []}
22 self.class.steps.add_to(self)
24 instance_eval(&block) if block
28 @hash_of_lists_of_steps[type].each do |step|
29 return step if step.matches?(name)
34 def GivenScenario(name, &block)
35 create_matcher(:given_scenario, name, &block)
38 def Given(name, &block)
39 create_matcher(:given, name, &block)
42 def When(name, &block)
43 create_matcher(:when, name, &block)
46 def Then(name, &block)
47 create_matcher(:then, name, &block)
50 alias :given_scenario :GivenScenario
56 (@hash_of_lists_of_steps[type] << steps).flatten!
60 @hash_of_lists_of_steps.clear
64 [:given_scenario, :given, :when, :then].each do |type|
65 return false unless @hash_of_lists_of_steps[type].empty?
70 def add_to(other_step_matchers)
71 [:given_scenario, :given, :when, :then].each do |type|
72 other_step_matchers.add(type, @hash_of_lists_of_steps[type])
76 def <<(other_step_matchers)
77 other_step_matchers.add_to(self) if other_step_matchers.respond_to?(:add_to)
80 # TODO - make me private
81 def create_matcher(type, name, &block)
82 matcher = Step.new(name, &block)
83 @hash_of_lists_of_steps[type] << matcher