36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/fast_context.rb', line 36
def create_test_from_should_hash
test_name = test_method_name
if test_unit_class.instance_methods.include?(test_name.to_s)
warn " * WARNING: '#{test_name}' is already defined"
end
context = self
test_unit_class.send(:define_method, test_name) do
@shoulda_context = context
@current_should = nil
begin
context.run_parent_setup_blocks(self)
context.shoulds.each do |s|
@current_should = s
s[:before].bind(self).call if s[:before]
end
context.run_current_setup_blocks(self)
context.shoulds.each {|should| should[:block].bind(self).call }
rescue Test::Unit::AssertionFailedError => e
error = Test::Unit::AssertionFailedError.new(["FAILED:", context.full_name, "should", "#{@current_should[:name]}:", e.message].flatten.join(' '))
error.set_backtrace e.backtrace
raise error
ensure
context.run_all_teardown_blocks(self)
end
end
end
|