|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -require "simplecov" |
4 |
| -require "simplecov-cobertura" |
5 |
| -require "codecov" |
6 |
| -require "ruby_llm" |
| 3 | +require 'simplecov' |
| 4 | +require 'simplecov-cobertura' |
| 5 | +require 'codecov' |
| 6 | +require 'vcr' |
7 | 7 |
|
8 | 8 | SimpleCov.start do
|
9 | 9 | enable_coverage :branch
|
10 | 10 |
|
11 | 11 | formatter SimpleCov::Formatter::MultiFormatter.new(
|
12 | 12 | [
|
13 | 13 | SimpleCov::Formatter::SimpleFormatter,
|
14 |
| - SimpleCov::Formatter::Codecov, |
15 |
| - SimpleCov::Formatter::CoberturaFormatter, |
16 |
| - ] |
| 14 | + (SimpleCov::Formatter::Codecov if ENV['CODECOV_TOKEN']), |
| 15 | + SimpleCov::Formatter::CoberturaFormatter |
| 16 | + ].compact |
17 | 17 | )
|
18 | 18 | end
|
19 | 19 |
|
20 |
| -require "active_record" |
21 |
| -require "bundler/setup" |
22 |
| -require "fileutils" |
| 20 | +require 'active_record' |
| 21 | +require 'bundler/setup' |
| 22 | +require 'fileutils' |
| 23 | +require 'ruby_llm' |
| 24 | +require 'webmock/rspec' |
| 25 | + |
| 26 | +# VCR Configuration |
| 27 | +VCR.configure do |config| |
| 28 | + config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' |
| 29 | + config.hook_into :webmock |
| 30 | + config.configure_rspec_metadata! |
| 31 | + |
| 32 | + # Don't record new HTTP interactions when running in CI |
| 33 | + config.default_cassette_options = { |
| 34 | + record: ENV['CI'] ? :none : :new_episodes |
| 35 | + } |
| 36 | + |
| 37 | + # Create new cassette directory if it doesn't exist |
| 38 | + FileUtils.mkdir_p(config.cassette_library_dir) |
| 39 | + |
| 40 | + # Allow HTTP connections when necessary - this will fail PRs by design if they don't have cassettes |
| 41 | + config.allow_http_connections_when_no_cassette = true |
| 42 | + |
| 43 | + # Filter out API keys from the recorded cassettes |
| 44 | + config.filter_sensitive_data('<OPENAI_API_KEY>') { ENV.fetch('OPENAI_API_KEY', nil) } |
| 45 | + config.filter_sensitive_data('<ANTHROPIC_API_KEY>') { ENV.fetch('ANTHROPIC_API_KEY', nil) } |
| 46 | + config.filter_sensitive_data('<GEMINI_API_KEY>') { ENV.fetch('GEMINI_API_KEY', nil) } |
| 47 | + config.filter_sensitive_data('<DEEPSEEK_API_KEY>') { ENV.fetch('DEEPSEEK_API_KEY', nil) } |
| 48 | + |
| 49 | + # Filter sensitive response headers |
| 50 | + config.filter_sensitive_data('<OPENAI_ORGANIZATION>') do |interaction| |
| 51 | + interaction.response.headers['Openai-Organization']&.first |
| 52 | + end |
| 53 | + config.filter_sensitive_data('<X_REQUEST_ID>') { |interaction| interaction.response.headers['X-Request-Id']&.first } |
| 54 | + config.filter_sensitive_data('<REQUEST_ID>') { |interaction| interaction.response.headers['Request-Id']&.first } |
| 55 | + config.filter_sensitive_data('<CF_RAY>') { |interaction| interaction.response.headers['Cf-Ray']&.first } |
| 56 | + |
| 57 | + # Filter cookies |
| 58 | + config.before_record do |interaction| |
| 59 | + if interaction.response.headers['Set-Cookie'] |
| 60 | + interaction.response.headers['Set-Cookie'] = interaction.response.headers['Set-Cookie'].map { '<COOKIE>' } |
| 61 | + end |
| 62 | + end |
| 63 | +end |
23 | 64 |
|
24 | 65 | RSpec.configure do |config|
|
25 | 66 | # Enable flags like --only-failures and --next-failure
|
|
34 | 75 | end
|
35 | 76 |
|
36 | 77 | config.around do |example|
|
37 |
| - cassette_name = example.full_description.parameterize(separator: "_").delete_prefix("rubyllm_") |
38 |
| - cassette_name = example.full_description.parameterize(separator: "_").delete_prefix("rubyllm_") |
| 78 | + cassette_name = example.full_description.parameterize(separator: '_').delete_prefix('rubyllm_') |
39 | 79 | VCR.use_cassette(cassette_name) do
|
40 | 80 | example.run
|
41 | 81 | end
|
|
0 commit comments