Class: Sidekiq::Sorbet::RSpec::Matchers::AcceptArgs

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/sorbet/rspec/matchers.rb

Overview

Matcher for validating that a worker accepts specific arguments

Examples:

expect(MyWorker).to accept_args(user_id: 123)
expect(MyWorker).to accept_args(user_id: 123, name: "Alice")

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ AcceptArgs

Returns a new instance of AcceptArgs.



181
182
183
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 181

def initialize(args)
  @args = args
end

Instance Method Details

#descriptionObject



207
208
209
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 207

def description
  "accept arguments #{@args.inspect}"
end

#failure_messageObject



198
199
200
201
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 198

def failure_message
  "expected #{@actual} to accept arguments #{@args.inspect}, " \
    "but it raised #{@raised_error.class}: #{@raised_error.message}"
end

#failure_message_when_negatedObject



203
204
205
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 203

def failure_message_when_negated
  "expected #{@actual} not to accept arguments #{@args.inspect}, but it did"
end

#matches?(worker_class) ⇒ Boolean

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 185

def matches?(worker_class)
  @actual = worker_class

  worker_class.send(:build_args, **@args)
  true
rescue Sidekiq::Sorbet::InvalidArgsError,
       Sidekiq::Sorbet::ArgsNotDefinedError,
       ArgumentError,
       TypeError => e
  @raised_error = e
  false
end