-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmiddleware_helpers.rb
51 lines (42 loc) · 1.28 KB
/
middleware_helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'cypress_on_rails/middleware_config'
module CypressOnRails
module Vcr
# Provides helper methods for VCR middlewares
module MiddlewareHelpers
include MiddlewareConfig
def vcr
@vcr ||= configure_vcr
end
def cassette_library_dir
configuration.vcr_options&.fetch(:cassette_library_dir) do
"#{configuration.install_folder}/fixtures/vcr_cassettes"
end
end
private
def configure_vcr
require 'vcr'
VCR.configure do |config|
config.cassette_library_dir = cassette_library_dir
apply_vcr_options(config) if configuration.vcr_options.present?
end
VCR
end
def apply_vcr_options(config)
configuration.vcr_options.each do |option, value|
next if option.to_sym == :cassette_library_dir
apply_vcr_option(config, option, value)
end
end
def apply_vcr_option(config, option, value)
return unless config.respond_to?(option) || config.respond_to?("#{option}=")
if config.respond_to?("#{option}=")
config.send("#{option}=", value)
elsif value.is_a?(Array)
config.send(option, *value)
else
config.send(option, value)
end
end
end
end
end