forked from crmne/ruby_llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_llm_spec.rb
More file actions
68 lines (56 loc) · 1.79 KB
/
ruby_llm_spec.rb
File metadata and controls
68 lines (56 loc) · 1.79 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RubyLLM do
describe '.logger' do
let(:logger) { instance_double(Logger) }
let(:log_file) { double }
let(:log_level) { double }
before do
described_class.instance_variable_set(:@config, nil)
described_class.instance_variable_set(:@logger, nil)
end
after do
described_class.instance_variable_set(:@config, nil)
described_class.instance_variable_set(:@logger, nil)
end
context 'with configuration options' do
before do
described_class.configure do |config|
config.log_file = log_file
config.log_level = log_level
end
end
it 'returns a default Logger' do
allow(Logger).to receive(:new).with(log_file, progname: 'RubyLLM', level: log_level).and_return(logger)
expect(described_class.logger).to eq(logger)
end
end
context 'with a custom logger' do
before do
described_class.configure do |config|
config.logger = logger
config.log_file = log_file
config.log_level = log_level
end
end
it 'returns a the custom Logger' do
expect(described_class.logger).to eq(logger)
end
end
context 'with RUBYLLM_LOG_FILE set' do
around do |example|
original_log_file = ENV.fetch('RUBYLLM_LOG_FILE', nil)
ENV['RUBYLLM_LOG_FILE'] = '/tmp/ruby_llm.log'
example.run
ensure
ENV['RUBYLLM_LOG_FILE'] = original_log_file
end
it 'uses the env var as the default log file' do
allow(Logger).to receive(:new)
.with('/tmp/ruby_llm.log', progname: 'RubyLLM', level: Logger::INFO)
.and_return(logger)
expect(described_class.logger).to eq(logger)
end
end
end
end