Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Used 64 times
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/xjNs3G"
Template Source
Review the code before running this template on your machine.
inject_into_file 'Gemfile', after: 'group :development, :test do' do
<<-RUBY
gem "vcr"
RUBY
end
after_bundle do
file 'spec/support/vcr.rb', <<~CODE
require "vcr"
VCR.configure do |config|
config.cassette_library_dir = Rails.root.join("spec/cassettes")
config.hook_into :webmock
config.configure_rspec_metadata!
config.default_cassette_options = { record: :once }
config.debug_logger = $stdout if ENV["VCR_DEBUG"]
end
RSpec.configure do |config|
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(
%r{[^\w/]+}, "_"
)
options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
VCR.use_cassette(name, options) { example.call }
end
end
CODE
end