I am writing tests with Rspec2 using a flash-based flash-based framework. I expect one of my methods to cache the results and want to test this using my layout.
describe SomeClass do
before do
@mock = flexmock()
end
after do
@mock.flexmock_verify()
end
it "method caches results"
c = SomeClass.new(@mock)
c.method
@mock.should_receive(:expensive_method).never
c.method.should == ['A']
end
end
This works well if I want to make sure it is :expensive_methodnever called. However, I expect my class to be able to do :methodwithout invoking anything from the class (mock). Is there any way to express this?
Background: . In my case, the class being introduced performs expensive operations, so the results should be cached for equal queries.
, , , , , , . , , - SomeClass :method:
def SomeClass
@@cache_map = {}
def method
return @@cache_map[key] if @@cache_map.has_key?(key)
@@cache_map[key] = result
return result
end
end
, , :extensive_method . , , : , SomeClass.method ( :expensive_method, - ).