Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] :memoized methods are stored in Klass.memoized_methods

#897

http://groups.google.com/group/r...


class MyKlass
  def something(n)
     return randomly(n)
  end
  memoize :something
end

class MyKlassTest
  test "something is declared as memoized" do
    assert MyKlass.memoized_methods.include?(:something)
  end

  test "something is memoized" do
     my_model.stubs(:randomly).returns(1,2,3)
     assert_equal 1, my_model.something(7)
     assert_equal 1, my_model.something(7)
     assert_equal 2, my_model.something(100)
  end
end

I've currently put the :memoized_methods method on the Klass, perhaps it should be on the record, or called :memoized_instance_methods.

But it feels that, as it's declared in the class scope, it should set :memoized_methods in the same scope.

Reported by MatthewRudy · August 25th, 2008 @ 10:41 AM

State: wontfix
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski
    • Assigned user set to josh

    I still feel that this is better handled by you writing your own assertion

    
    def assert_memoized(object, method)
      assert object.respond_to? "_unmemoized_#{method}"
    end
    

    Changing the implementation just to suit tests seems broken.

    August 25th, 2008 @ 03:03 PM

  2. josh
    josh
    • State changed from new to wontfix

    You might want to add some test coverage for mixins, inheritance, and extending objects. You might find an instance variable just won't work how you except it. Seriously, I tried this approach when I first wrote this helper.

    August 25th, 2008 @ 04:18 PM

  3. MatthewRudy
    MatthewRudy

    hmm, yeah. maybe Mr Koz.

    I still don't understand why this doesn't use alias_method_chain, though.

    I may just abandon using :memoize anyway, as it doesn't seem like the best idea in the world.

    I still see a use in asserting that a rails method has been used.

    eg.

    Model.should have_many(:sausages).with(:conditions => {:tasty => true})

    is useful.

    Although, I guess my particular brand of testing logic is distinct from yours.

    Take it easy. Will nudge you at RailsConf in a week-ish

    August 26th, 2008 @ 01:01 AM