Add VCR and some initial tests

This commit is contained in:
Jorge Manrubia
2025-05-16 12:54:00 +02:00
parent 4c7b99e39d
commit b8f94c4ecb
18 changed files with 6838 additions and 115 deletions
+35
View File
@@ -0,0 +1,35 @@
# To include in those tests that use VCR. It will automatically insert a VCR cassette named after the test. By default,
# it will run the test in "replay" mode. To switch to record mode, you can either:
#
# * Set the environment variable +VCR_RECORD+.
# * Use +.vcr_record!+ in your test class.
module VcrTestHelper
extend ActiveSupport::Concern
included do
class_attribute :vcr_record
setup do
VCR.insert_cassette "#{self.class.name.tableize.singularize}-#{name}",
record: recording? ? :all : :none,
preserve_exact_body_bytes: true
end
teardown do
VCR.eject_cassette
end
def recording?
vcr_record || ENV["VCR_RECORD"]
end
end
class_methods do
# Use to force record mode at development time: always perform real http interactions and record fixtures
def vcr_record!
raise "#vcr_record! is meant for dev time. You are not supposed to run it in CI." if ENV["CI"]
self.vcr_record = true
end
end
end