Skip to content

Commit

Permalink
fix: configuration validation and test coverage setup
Browse files Browse the repository at this point in the history
- Fix Configuration class to properly validate API key
- Update Client class initialization to handle missing API key
- Configure SimpleCov for proper test coverage reporting
- Add CodeClimate test coverage integration
  • Loading branch information
nagstler committed Feb 2, 2025
1 parent 2646644 commit 86198d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/deepseek/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(api_key: nil, **options)
options.each do |key, value|
@config.send("#{key}=", value) if @config.respond_to?("#{key}=")
end
@config.validate!
@config.validate! # This will raise ConfigurationError if no API key is set
end

def chat(messages:, model: 'deepseek-chat', **params)
Expand Down
3 changes: 2 additions & 1 deletion lib/deepseek/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ def initialize
@api_base_url = ENV['DEEPSEEK_API_BASE_URL'] || 'https://api.deepseek.com'
@timeout = ENV['DEEPSEEK_TIMEOUT']&.to_i || 30
@max_retries = ENV['DEEPSEEK_MAX_RETRIES']&.to_i || 3
validate! unless api_key.nil? # Don't validate during initialization
end

def validate!
raise ConfigurationError, 'API key must be set' if api_key.nil? || api_key.empty?
raise ConfigurationError, 'API key must be set' if api_key.nil? || api_key.strip.empty?
end
end
end
35 changes: 18 additions & 17 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
require 'simplecov'
require 'simplecov-cobertura'

# Configure SimpleCov
SimpleCov.start do
enable_coverage :branch

add_filter '/spec/'
add_filter '/vendor/'

add_group 'Client', 'lib/deepseek/client'
add_group 'Configuration', 'lib/deepseek/configuration'
add_group 'Errors', 'lib/deepseek/errors'
enable_coverage :branch

# Add groups for better organization
add_group 'Client', 'lib/deepseek/client.rb'
add_group 'Configuration', 'lib/deepseek/configuration.rb'
add_group 'Errors', 'lib/deepseek/errors.rb'

track_files 'lib/**/*.rb'
end

# Set formatter for CodeClimate
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::CoberturaFormatter
Expand All @@ -21,22 +26,18 @@
require 'webmock/rspec'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.expect_with :rspec do |c|
c.syntax = :expect
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

# Clean up after each test
config.after(:each) do
Deepseek.reset_configuration!
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

# Configure WebMock
config.shared_context_metadata_behavior = :apply_to_host_groups
config.order = :random
config.example_status_persistence_file_path = "spec/examples.txt"

config.before(:each) do
WebMock.disable_net_connect!
end
Expand Down

0 comments on commit 86198d9

Please sign in to comment.