Disons que nous avons une classe:Comment la méthode simulée avec des attentes quant à ce qui est passé au bloc
class ObjectWithCaching
def cached_attribute(key, cache_handler)
cache_handler.cache(key) { expensive_operation }
end
def expensive_operation
#...
end
end
Et nous cache_handler déjà testé, donc nous savons qu'il exécutera le bloc que lorsque key
est introuvable au cache
.
Nous voulons tester si cache_handler # cache est correctement exécuté.
La question est: Comment écrire reste en attente?
describe ObjectWithCaching, "#cached_attribute" do
let(:key) { double }
let(:cache_handler) { double }
specify do
cache_handler.should_receive(:cache).with(key)
subject.cached_attribute(key, cache_handler)
end
it "passes #expensive_operation to block of cache_handler#cache" do
pending
subject.cached_attribute(key, cache_handler)
end
end
Sons raisonnables. Stubbing cost_operation dans cet exemple est ok à mon avis. – mehowte
Il semble que le cache de blocage pour toujours appeler le bloc est le chemin à parcourir. Merci. – mehowte