diff --git a/lib/speed_limiter/throttle_params.rb b/lib/speed_limiter/throttle_params.rb index 9403869..f5eb2f9 100644 --- a/lib/speed_limiter/throttle_params.rb +++ b/lib/speed_limiter/throttle_params.rb @@ -5,12 +5,18 @@ module SpeedLimiter # Throttle params model class ThrottleParams + KNOWN_OPTIONS = %i[on_throttled retry].freeze + def initialize(config:, key:, limit:, period:, **options) @config = config @key = key @limit = limit @period = period @options = options + + return unless (unknown_options = options.keys - KNOWN_OPTIONS).any? + + raise ArgumentError, "Unknown options: #{unknown_options.join(', ')}" end attr_reader :config, :key, :limit, :period diff --git a/spec/speed_limiter/throttle_params_spec.rb b/spec/speed_limiter/throttle_params_spec.rb new file mode 100644 index 0000000..4f1dc02 --- /dev/null +++ b/spec/speed_limiter/throttle_params_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe SpeedLimiter::Throttle do + let!(:config) { SpeedLimiter::Config.new } + + describe "#new" do + context "with unknown options" do + it "raises ArgumentError" do + expect { described_class.new(config: config, key: SecureRandom.uuid, limit: 1, period: 1, unknown: true) } + .to raise_error(ArgumentError) + end + end + end +end