Skip to content

Instantly share code, notes, and snippets.

@rmw
Created June 18, 2012 18:32
Show Gist options
  • Save rmw/2949882 to your computer and use it in GitHub Desktop.
Save rmw/2949882 to your computer and use it in GitHub Desktop.
Using tap to DRY up Rspec
def cache_should_receive_fetch(return_val = nil)
Rails.cache.should_receive(:fetch).
with(cache_key, { :race_condition_ttl => 10}).
tap { |o| o.and_return(return_val) unless return_val.nil? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment