VCR-like cache #7

Merged
merged 12 commits into from Mar 17, 2013

Conversation

Projects
None yet
3 participants
Collaborator

Swizec commented Mar 14, 2013

Hey,

I prefer VCR to manually mocking every API under the sun and I wanted to use it when testing javascript that makes API requests.

Since that's impossible I improved puffing-billy to do that.

Things added:

  • ability to persist cache
  • ability to ignore parameters on some requests
  • caching different types of requests
  • added all of the above to README

In essence this means you can take frontend tests completely offline without mocking out every analytics and social button thing on your website and with full support for repeatable tests when Javascript talks to 3rd parties (stripe, balanced, and so on).

The ignoring parameters part is important because it makes things like google analytics and social buttons cacheable since they don't really affect tests, but do make a 3rd party request and always with a different URL.

I've also added tests for all of this to the best of my abilities.

Cheers,
~Swizec

Yes, please.

@oesmith oesmith merged commit 358ea75 into oesmith:master Mar 17, 2013

Owner

oesmith commented Mar 17, 2013

Great stuff, and it all worked straight away on some big rails projects I tried it on -- very impressive 👍

A couple of small comments:

  • Prefer do .. end on multiline blocks instead of curlies.
  • Having a config flag and a method to call to set up the persistent cache is one step too many, imho. I'm sure we can find a cleaner way to do it 😄

Since this has been a great addition (and a very clean PR), I've added you as a collaborator on the repo. Feel free to push changes you're confident with. Otherwise, open a pull request for discussion as usual.

THANKS!

Collaborator

Swizec commented Mar 17, 2013

Yay \o/

Any particular reason why do ... end is better than curly brackets?

As for the setup, in theory setting the flag should be enough. But for some reason the proxy is instantiated before spec_helper runs your config, which means that when it's spinning up the flag isn't set yet and it doesn't read the cache from YAML files. So unless you reload the cache manually, it will not be there first time requests are made.

I couldn't figure out how to fix this one ...

Owner

oesmith commented Mar 31, 2013

do ... end is mostly just a style convention. There are some odd precedence
differences between curlies and do...ends, but you're not likely to get
tripped up by those very often.

I think we can probably do some extra work in the configure method to
detect changes in the flag and reloads the cache if its enabled.
On Sun, Mar 17, 2013 at 11:19 PM, Swizec Teller notifications@github.com
wrote:

Yay \o/

Any particular reason why do ... end is better than curly brackets?

As for the setup, in theory setting the flag should be enough. But for
some reason the proxy is instantiated before spec_helper runs your config,
which means that when it's spinning up the flag isn't set yet and it
doesn't read the cache from YAML files. So unless you reload the cache
manually, it will not be there first time requests are made.

I couldn't figure out how to fix this one ...


Reply to this email directly or view it on GitHubhttps://github.com/oesmith/puffing-billy/pull/7#issuecomment-15033397
.

@decareano decareano referenced this pull request in Proskurina/doit_rails Jan 9, 2016

Open

Billy only #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment