Skip to content

Commit 936d23d

Browse files
committed
StripeHelper
1 parent 27f2a36 commit 936d23d

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

spec/support/capybara.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
# --------------
2929
# http://www.rubydoc.info/github/jnicklas/capybara/master
3030
# Cheatsheet: https://gist.github.com/zhengjia/428105
31-
# Capybara matchers: http://www.rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers
31+
# Capybara matchers: http://www.rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers

spec/support/puffing_billy.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,45 @@
2424
c.non_successful_error_level = :warn
2525

2626
# cache_path is where responses from external URLs will be saved as YAML.
27-
c.cache_path = "spec/support/http_cache/frontend/"
27+
c.cache_path = "spec/support/http_cache/frontend/"
2828

2929
# Avoid having tests dependent on external URLs.
3030
#
3131
# Only set non_whitelisted_requests_disabled **temporarily**
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+
c.non_whitelisted_requests_disabled = false
36+
end
37+
38+
# https://github.com/oesmith/puffing-billy#working-with-vcr-and-webmock
39+
if defined?(VCR)
40+
VCR.configure do |config|
41+
config.ignore_request { |request| handled_by_billy?(request) }
42+
end
43+
44+
def handled_by_billy?(request)
45+
# browser_referer?(request)
46+
browser_user_agent?(request)
47+
end
48+
49+
def browser_user_agent?(request)
50+
user_agent = !request.headers["User-Agent"].blank? && request.headers["User-Agent"].first
51+
is_real_browser_user_agent = user_agent != "Ruby"
52+
end
53+
54+
# def allowed_referers
55+
# [
56+
# %r{\Ahttp://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/},
57+
# %r{\Ahttps://checkout\.stripe\.com},
58+
# %r{\Ahttps://b\.stripecdn\.com}
59+
# ]
60+
# end
61+
62+
# def browser_referer?(request)
63+
# referer = !request.headers["Referer"].blank? && request.headers["Referer"].first
64+
# handled = referer && allowed_referers.any? { |pattern| pattern =~ referer }
65+
# end
3666
end
3767

3868
# 5. Uncomment the *_billy driver for your desired browser:

spec/support/stripe_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module StripeHelper
2+
3+
def fill_in_with_force(locator, options)
4+
page.execute_script "$('#{locator}').val('#{options[:with]}');"
5+
end
6+
7+
alias_method :fill_in_stripe_field, :fill_in_with_force
8+
9+
end
10+
11+
RSpec.configure do |config|
12+
config.include StripeHelper, type: :feature
13+
end

0 commit comments

Comments
 (0)