lib/shoulda/context/context.rb in shoulda-context-1.2.1 vs lib/shoulda/context/context.rb in shoulda-context-1.2.2
- old
+ new
@@ -208,11 +208,13 @@
# # => User
def described_type
@described_type ||= self.name.
gsub(/Test$/, '').
split('::').
- inject(Object) { |parent, local_name| parent.const_get(local_name) }
+ inject(Object) do |parent, local_name|
+ parent.const_get(local_name, false)
+ end
end
# Sets the return value of the subject instance method:
#
# class UserTest < Test::Unit::TestCase
@@ -392,34 +394,34 @@
if test_methods[test_unit_class][test_name.to_s] then
raise DuplicateTestError, "'#{test_name}' is defined more than once."
end
test_methods[test_unit_class][test_name.to_s] = true
-
+ file, line_no = should[:block].source_location
context = self
- test_unit_class.send(:define_method, test_name) do
+ test_unit_class.class_eval <<-end_eval, file, line_no
+ define_method test_name do
@shoulda_context = context
begin
context.run_parent_setup_blocks(self)
if should[:before]
if self.respond_to?(:instance_exec)
self.instance_exec(&should[:before])
else
- # deprecated in Rails 4.x
should[:before].bind(self).call
end
end
context.run_current_setup_blocks(self)
if self.respond_to?(:instance_exec)
self.instance_exec(&should[:block])
else
- # deprecated in Rails 4.x
should[:block].bind(self).call
end
ensure
context.run_all_teardown_blocks(self)
end
- end
+ end
+ end_eval
end
def run_all_setup_blocks(binding)
run_parent_setup_blocks(binding)
run_current_setup_blocks(binding)