lambda.cx blog Sharing notes with the internet
Posts with the tag Ruby:

Lesser Known IRB Features

While poking around in IRB and looking at the autocompletion results, I found some functions that I didn't recognize and decided to take a look at what they do. I found some pretty interesting stuff. It looks like some of these commands have been added recently to come up to par with pry, and others have been kicking around for a while and just flying under the radar. You can find them all defined in this file in the IRB source code.

Testing Rails Components That Require Cache

If you're in the default testing environment your rails cache is ActiveSupport::Cache::NullStore which will always succeed but it doesn't actually store or return anything. There's an almost completely undocumented method called with_local_cache on NullStore that lets you run a block with a MemoryStore instead of a NullStore for the duration of the block. This happens because it prepends the ActiveSupport::Cache::Strategy::LocalCache class. This lets you test one or two things that require caching without enabling it on all tests and slowing everything down.