Browse files

Maintain cache of test methods. Improved from exponential to contant …

…time

Signed-off-by: Ryan McGeary <ryanongit@mcgeary.org>
  • Loading branch information...
1 parent 02520e4 commit bcdf8c7a1980b83c67c06cdaa1576a3638608123 @zenspider zenspider committed with rmm5t Sep 12, 2010
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/shoulda/context.rb
View
10 lib/shoulda/context.rb
@@ -365,13 +365,21 @@ def test_unit_class
am_subcontext? ? parent.test_unit_class : parent
end
+ def test_methods
+ @test_methods ||= Hash.new { |h,k|
+ h[k] = Hash[k.instance_methods.map { |n| [n, true] }]

This works on Ruby 1.8.7, but not Ruby 1.8.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+ end
+
def create_test_from_should_hash(should)
test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym
- if test_unit_class.instance_methods.include?(test_name.to_s)
+ if test_methods[test_unit_class][test_name.to_s] then
warn " * WARNING: '#{test_name}' is already defined"
end
+ test_methods[test_unit_class][test_name.to_s] = true
+
context = self
test_unit_class.send(:define_method, test_name) do
@shoulda_context = context

0 comments on commit bcdf8c7

Please sign in to comment.