Skip to content

Commit

Permalink
Puffing Billy+VCR user-agent ignore host logic and BILLY_RECORDING en…
Browse files Browse the repository at this point in the history
…v var
  • Loading branch information
eliotsykes committed Dec 11, 2015
1 parent 75cc8ed commit d011d51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Capybara configuration how-to and examples:
If you need to debug Puffing Billy, refer to its output in `log/test.log`.

Puffing Billy configuration how-to and examples:
- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb)
- [spec/support/puffing_billy.rb](spec/support/puffing_billy.rb) - see comments on recording responses with `BILLY_RECORDING` environment variable
- [spec/features/share_page_spec.rb](spec/features/share_page_spec.rb)
- [Cache options](https://github.com/oesmith/puffing-billy#caching)
- [Cached responses in spec/support/http_cache/frontend](spec/support/http_cache/frontend)
Expand Down
17 changes: 13 additions & 4 deletions spec/support/puffing_billy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
# to false when first recording a 3rd party interaction. After
# the recording has been stored to cache_path, then set
# non_whitelisted_requests_disabled back to true.
c.non_whitelisted_requests_disabled = true
#
# To enable recording new responses temporarily, run the individual spec
# and prepend with BILLY_RECORDING set to true:
# BILLY_RECORDING=true bin/rspec spec/features/user_upgrades_spec.rb
prevent_recording = ('true' != ENV['BILLY_RECORDING'])
c.non_whitelisted_requests_disabled = prevent_recording
end

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

def handled_by_billy?(request)
# browser_referer?(request)
browser_user_agent?(request)
browser_user_agent?(request) && browser_test_in_progress?
end

def browser_user_agent?(request)
user_agent = !request.headers["User-Agent"].blank? && request.headers["User-Agent"].first
is_real_browser_user_agent = user_agent != "Ruby"
user_agent != "Ruby"
end

def browser_test_in_progress?
Capybara.current_driver != :rack_test
end

# def allowed_referers
Expand All @@ -61,7 +70,7 @@ def browser_user_agent?(request)

# def browser_referer?(request)
# referer = !request.headers["Referer"].blank? && request.headers["Referer"].first
# handled = referer && allowed_referers.any? { |pattern| pattern =~ referer }
# referer && allowed_referers.any? { |pattern| pattern =~ referer }
# end
end

Expand Down

0 comments on commit d011d51

Please sign in to comment.