Module: Bacon::ContextAssertions

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

Instance Method Summary collapse

Instance Method Details

#create_context(name, &block) ⇒ Object



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

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

#execute_spec(&block) ⇒ Object



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

def execute_spec(&block)
  block.call
end

#runObject



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

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

#run_requirement(description, spec) ⇒ Object



113
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
# File 'lib/bacon.rb', line 113

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
      raise
      
    rescue Object => e
      Bacon.store_error(e, description)
    else
      ""
    ensure
      Counter[:depth] -= 1
    end
  end
end