Skip to content

Commit

Permalink
Maintain cache of test methods. Improved from exponential to contant …
Browse files Browse the repository at this point in the history
…time

Signed-off-by: Ryan McGeary <ryanongit@mcgeary.org>
  • Loading branch information
zenspider authored and rmm5t committed Sep 15, 2010
1 parent 02520e4 commit bcdf8c7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/shoulda/context.rb
Expand Up @@ -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 comment has been minimized.

Copy link
@snowblink

snowblink Sep 22, 2010

Contributor

This works on Ruby 1.8.7, but not Ruby 1.8.6

}
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
Expand Down

0 comments on commit bcdf8c7

Please sign in to comment.