Class: Spec::Story::StepGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_defaults = true, &block) ⇒ StepGroup

Returns a new instance of StepGroup.



19
20
21
22
23
24
25
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 19

def initialize(init_defaults=true, &block)
  @hash_of_lists_of_steps = Hash.new {|h, k| h[k] = []}
  if init_defaults
    self.class.steps.add_to(self)
  end
  instance_eval(&block) if block
end

Class Method Details

.steps(&block) ⇒ Object



13
14
15
16
17
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 13

def self.steps(&block)
  @step_group ||= StepGroup.new(false)
  @step_group.instance_eval(&block) if block
  @step_group
end

Instance Method Details

#<<(other_step_matchers) ⇒ Object



76
77
78
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 76

def <<(other_step_matchers)
  other_step_matchers.add_to(self) if other_step_matchers.respond_to?(:add_to)
end

#add(type, steps) ⇒ Object



55
56
57
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 55

def add(type, steps)
  (@hash_of_lists_of_steps[type] << steps).flatten!
end

#add_to(other_step_matchers) ⇒ Object



70
71
72
73
74
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 70

def add_to(other_step_matchers)
  [:given_scenario, :given, :when, :then].each do |type|
    other_step_matchers.add(type, @hash_of_lists_of_steps[type])
  end
end

#clearObject



59
60
61
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 59

def clear
  @hash_of_lists_of_steps.clear
end

#create_matcher(type, name, &block) ⇒ Object

TODO - make me private



81
82
83
84
85
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 81

def create_matcher(type, name, &block)
  matcher = Step.new(name, &block)
  @hash_of_lists_of_steps[type] << matcher
  matcher
end

#empty?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 63

def empty?
  [:given_scenario, :given, :when, :then].each do |type|
    return false unless @hash_of_lists_of_steps[type].empty?
  end
  return true
end

#find(type, name) ⇒ Object



27
28
29
30
31
32
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 27

def find(type, name)
  @hash_of_lists_of_steps[type].each do |step|
    return step if step.matches?(name)
  end
  return nil
end

#Given(name, &block) ⇒ Object Also known as: given



38
39
40
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 38

def Given(name, &block)
  create_matcher(:given, name, &block)
end

#GivenScenario(name, &block) ⇒ Object Also known as: given_scenario



34
35
36
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 34

def GivenScenario(name, &block)
  create_matcher(:given_scenario, name, &block)
end

#Then(name, &block) ⇒ Object Also known as: then



46
47
48
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 46

def Then(name, &block)
  create_matcher(:then, name, &block)
end

#When(name, &block) ⇒ Object Also known as: when



42
43
44
# File 'lib/gems/rspec-1.1.12/lib/spec/story/step_group.rb', line 42

def When(name, &block)
  create_matcher(:when, name, &block)
end