ruby on rails - How to spec operations that rely on Memcached? -


we have rails application test rspec. want spec operations rely on memcached. best practice so?

i thought of doing stubbing calls rails.cache. idea?

as per @pan thomakos suggestion, i'm adding additional details 1 of scenarios i'm trying test:

we have concept of accounts in our system, therefore on every request retrieve current user , current account. because there not many accounts in system, keep them in cache , retrieve them there.

def self.find_by_slug(slug)     rails.cache.fetch(account.cache_key_for_slug(slug), :expires_in => 1.day) { super }   end 

for reason, caching in case isn't nice have behavior, expected behavior , thing want test. therefore turning off caching won't do.

test without stubbing imho!

the sequence this:

  1. cache.flush # or equivalent
  2. cache.get(slug).shouldbe null # test cache empty
  3. method.find_by_slug(slug).should == 'some value' # test method words
  4. cache.get(slug).should == 'some value' # test cache has value.

personally, believe if have resources on hand stubbing should not used. if not have resources on hand (ie 3rd party service) stubbing should used.

the problem stubbing, if changed code stubbing, won't know if breaks.

an example in case if switched standard memcache gem, dahli?, or other memcache gem handed cache misses returning false, null or other value differently. mean really! cache.set("my_key", false)! :)

a example switching, leave ascii protocol , move faster binary protocol.

memcache cheap resource, can set 1 meg of ram testing. go far can same mysql. bigger mysql, start leaning towards stubbing cost "setup" resources becomes significant. ymmv.

-daniel


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -