Created
October 17, 2012 07:08
-
-
Save samwgoldman/3904149 to your computer and use it in GitHub Desktop.
How to use VCR even if your tests depend on Date.today/Time.now, +/- 100 days/seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VCR.configure do |config| | |
config.cassette_library_dir = "spec/cassettes" | |
config.hook_into :faraday | |
# If a test uses a value that depends on the current time, then the recording | |
# become stale as time marches on. | |
# This setting will replace specific "absolute time" values with time-relative | |
# keywords when the recording is first made. | |
# On subsequent replayes, the time-relative keywords are substituted with | |
# the appropriate value, so the value is relative tot he current time. | |
(-100..100).each do |offset| | |
date = Date.today + offset | |
time = Time.now + offset | |
config.define_cassette_placeholder("<YYYYMMDD+#{offset}>") { date.to_s } | |
config.define_cassette_placeholder("<HTTPDATE+#{offset}>") { time.httpdate } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment