Module: Bacon::ContextAssertions

Included in:
Context
Defined in:
lib/bacon.rb

Instance Method Summary collapse

Instance Method Details

#create_context(name, &block) ⇒ Object



158
159
160
# File 'lib/bacon.rb', line 158

def create_context(name, &block)
  Bacon::Context.new(name, &block)
end

#execute_spec(&block) ⇒ Object



110
111
112
# File 'lib/bacon.rb', line 110

def execute_spec(&block)
  block.call
end

#runObject



162
163
164
165
166
167
# File 'lib/bacon.rb', line 162

def run
  Counter[:context_depth] += 1
  Bacon.handle_specification(name) { instance_eval(&block) }
  Counter[:context_depth] -= 1
  self
end

#run_requirement(description, spec) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/bacon.rb', line 114

def run_requirement(description, spec)
  Bacon.handle_requirement description do |timing|
    begin
      Counter[:depth] += 1
      rescued = false
      begin
        prev_req = nil
        
        execute_spec do
          timing << Hitimes::Interval.measure do
            @before.each { |block| instance_eval(&block) }
          end
          
          timing << Hitimes::Interval.measure do
            prev_req = Counter[:requirements]
            instance_eval(&spec)
          end
        end
      rescue Object => e
        rescued = true
        raise e
      ensure
        if Counter[:requirements] == prev_req and not rescued
          raise Error.new(:missing, "empty specification: #{@name} #{description}")
        end
        begin
          @after.each { |block| instance_eval(&block) }
        rescue Object => e
          raise e  unless rescued
        end
      end
    rescue Interrupt, SystemExit
      raise
      
    rescue Object => e
      Bacon.store_error(e, description)
    else
      ""
    ensure
      Counter[:depth] -= 1
    end
  end
end