Skip to content

Commit d011d51

Browse files
committed
Puffing Billy+VCR user-agent ignore host logic and BILLY_RECORDING env var
1 parent 75cc8ed commit d011d51

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Capybara configuration how-to and examples:
169169
If you need to debug Puffing Billy, refer to its output in `log/test.log`.
170170

171171
Puffing Billy configuration how-to and examples:
172-
- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb)
172+
- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb) - see comments on recording responses with `BILLY_RECORDING` environment variable
173173
- [spec/features/share_page_spec.rb](spec/features/share_page_spec.rb)
174174
- [Cache options](https://github.com/oesmith/puffing-billy#caching)
175175
- [Cached responses in spec/support/http_cache/frontend](spec/support/http_cache/frontend)

spec/support/puffing_billy.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
# to false when first recording a 3rd party interaction. After
3333
# the recording has been stored to cache_path, then set
3434
# non_whitelisted_requests_disabled back to true.
35-
c.non_whitelisted_requests_disabled = true
35+
#
36+
# To enable recording new responses temporarily, run the individual spec
37+
# and prepend with BILLY_RECORDING set to true:
38+
# BILLY_RECORDING=true bin/rspec spec/features/user_upgrades_spec.rb
39+
prevent_recording = ('true' != ENV['BILLY_RECORDING'])
40+
c.non_whitelisted_requests_disabled = prevent_recording
3641
end
3742

3843
# https://github.com/oesmith/puffing-billy#working-with-vcr-and-webmock
@@ -43,12 +48,16 @@
4348

4449
def handled_by_billy?(request)
4550
# browser_referer?(request)
46-
browser_user_agent?(request)
51+
browser_user_agent?(request) && browser_test_in_progress?
4752
end
4853

4954
def browser_user_agent?(request)
5055
user_agent = !request.headers["User-Agent"].blank? && request.headers["User-Agent"].first
51-
is_real_browser_user_agent = user_agent != "Ruby"
56+
user_agent != "Ruby"
57+
end
58+
59+
def browser_test_in_progress?
60+
Capybara.current_driver != :rack_test
5261
end
5362

5463
# def allowed_referers
@@ -61,7 +70,7 @@ def browser_user_agent?(request)
6170

6271
# def browser_referer?(request)
6372
# referer = !request.headers["Referer"].blank? && request.headers["Referer"].first
64-
# handled = referer && allowed_referers.any? { |pattern| pattern =~ referer }
73+
# referer && allowed_referers.any? { |pattern| pattern =~ referer }
6574
# end
6675
end
6776

0 commit comments

Comments
 (0)