Skip to content

Commit

Permalink
Merge pull request oesmith#97 from springleaf/0-5-0
Browse files Browse the repository at this point in the history
v0.5.0
  • Loading branch information
ronwsmith committed Feb 23, 2015
2 parents f7d55df + 3c68350 commit 0eee0aa
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v0.5.0, 2015-02-22
------------------

* Rubocop code cleanup (#89)
* Create option for strip query params in request stub (#93)
* Require compatible version of em-http-request (#94)

v0.4.1, 2015-01-02
------------------

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PATH
remote: .
specs:
puffing-billy (0.4.1)
puffing-billy (0.5.0)
addressable
em-http-request
em-http-request (~> 1.1.0)
em-synchrony
eventmachine
eventmachine_httpserver
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ It's good practice to reset the driver after each scenario, so having an
stubs are reset after each step, so any usage of a stub should be in the
same step that it was created in.

## Minitest Usage

Please see [this link](https://gist.github.com/sauy7/1b081266dd453a1b737b) for
details and report back to [Issue #49](https://github.com/oesmith/puffing-billy/issues/49)
if you get it fully working.

## Caching

Requests routed through the external proxy are cached.
Expand Down Expand Up @@ -202,6 +208,12 @@ caching. You should mostly use this for analytics and various social buttons as
they use cache avoidance techniques, but return practically the same response
that most often does not affect your test results.

`c.strip_query_params` is used to strip query parameters when you stub some requests
with query parameters. Default value is true. For example, `proxy.stub('http://myapi.com/user/?country=FOO')`
is considered the same as: `proxy.stub('http://myapi.com/user/?anything=FOO')` and
generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to distinguish between all these requests,
you may set this config value to false.

`c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
returns `bar({"some": "json"});` and is recorded, then a later request to
Expand Down Expand Up @@ -327,7 +339,7 @@ and tell it to ignore SSL certificate warnings. See
to see how Billy's default drivers are configured.

## Working with VCR and Webmock
If you use VCR and Webmock elsewhere in your specs, you will need to disable them
If you use VCR and Webmock elsewhere in your specs, you may need to disable them
for your specs utilizing Puffing Billy. To do so, you can configure your `spec_helper.rb`
as shown below:

Expand All @@ -341,6 +353,12 @@ RSpec.configure do |config|
end
```

## Resources

* [Bring Ruby VCR to Javascript testing with Capybara and puffing-billy](http://architects.dzone.com/articles/bring-ruby-vcr-javascript)
* [Integration Testing Stripe.js With Mocked Network Requests](http://dev.contractual.ly/testing-stripe-js-with-mocked-network/)
* [Clean-up unused cache files periodically with this config](https://github.com/oesmith/puffing-billy/pull/26#issuecomment-29905030)

## FAQ

1. Why name it after a train?
Expand Down
4 changes: 3 additions & 1 deletion lib/billy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Config
attr_accessor :logger, :cache, :cache_request_headers, :whitelist, :path_blacklist, :ignore_params,
:persist_cache, :ignore_cache_port, :non_successful_cache_disabled, :non_successful_error_level,
:non_whitelisted_requests_disabled, :cache_path, :proxy_port, :proxied_request_inactivity_timeout,
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :merge_cached_responses_whitelist
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :merge_cached_responses_whitelist,
:strip_query_params

def initialize
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand All @@ -34,6 +35,7 @@ def reset
@proxy_port = RANDOM_AVAILABLE_PORT
@proxied_request_inactivity_timeout = 10 # defaults from https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts
@proxied_request_connect_timeout = 5
@strip_query_params = true
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/billy/proxy_request_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def matches?(method, url)
if @url.is_a?(Regexp)
url.match(@url)
else
url.split('?')[0] == @url
Billy.config.strip_query_params ? (url.split('?')[0] == @url) : (url == @url)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/billy/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Billy
VERSION = '0.4.1'
VERSION = '0.5.0'
end
2 changes: 1 addition & 1 deletion puffing-billy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'addressable'
gem.add_runtime_dependency 'eventmachine'
gem.add_runtime_dependency 'em-synchrony'
gem.add_runtime_dependency 'em-http-request'
gem.add_runtime_dependency 'em-http-request', '~> 1.1.0'
gem.add_runtime_dependency 'eventmachine_httpserver'
gem.add_runtime_dependency 'http_parser.rb', '~> 0.6.0'
gem.add_runtime_dependency 'multi_json'
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/billy/proxy_request_stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
end
end

context "#matches? (with strip_query_params false in config)" do
before do
Billy.config.strip_query_params = false
end

it 'should not match up to request with query strings' do
stub = Billy::ProxyRequestStub.new('http://example.com/foo/bar/')
expect(stub.matches?('GET', 'http://example.com/foo/')).to_not be
expect(stub.matches?('GET', 'http://example.com/foo/bar/')).to be
expect(stub.matches?('GET', 'http://example.com/foo/bar/?baz=bap')).to_not be
end
end

context '#call (without #and_return)' do
let(:subject) { Billy::ProxyRequestStub.new('url') }

Expand Down

0 comments on commit 0eee0aa

Please sign in to comment.