Class: RSpec::Sidekiq::Matchers::Base Private
- Inherits:
-
Object
- Object
- RSpec::Sidekiq::Matchers::Base
- Includes:
- Matchers::Composable, Mocks::ArgumentMatchers, ArgumentNormalization, CountExpectation
- Defined in:
- lib/rspec/sidekiq/matchers/base.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Instance Attribute Summary collapse
- #actual_jobs ⇒ Object readonly private
- #expected_arguments ⇒ Object readonly private
- #expected_count ⇒ Object readonly private
- #expected_options ⇒ Object readonly private
- #klass ⇒ Object readonly private
Instance Method Summary collapse
- #at(timestamp) ⇒ Object private
- #at_least(n) ⇒ Object private
- #at_most(n) ⇒ Object private
- #common_message ⇒ Object private
- #description ⇒ Object private
- #exactly(n) ⇒ Object private
- #failure_message ⇒ Object private
- #failure_message_when_negated ⇒ Object private
- #formatted(thing) ⇒ Object private
- #immediately ⇒ Object private
- #in(interval) ⇒ Object private
-
#initialize ⇒ Base
constructor
private
A new instance of Base.
- #never ⇒ Object private
- #on(queue) ⇒ Object private
- #once ⇒ Object private
- #prefix_message ⇒ Object private
- #thrice ⇒ Object private
- #times ⇒ Object (also: #time) private
- #twice ⇒ Object private
- #with(*expected_arguments) ⇒ Object private
- #with_context(**kwargs) ⇒ Object private
Constructor Details
#initialize ⇒ Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Base.
254 255 256 257 258 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 254 def initialize @expected_arguments = [any_args] @expected_options = {} set_expected_count :positive, 1 end |
Instance Attribute Details
#actual_jobs ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
252 253 254 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 252 def actual_jobs @actual_jobs end |
#expected_arguments ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
252 253 254 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 252 def expected_arguments @expected_arguments end |
#expected_count ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
252 253 254 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 252 def expected_count @expected_count end |
#expected_options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
252 253 254 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 252 def @expected_options end |
#klass ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
252 253 254 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 252 def klass @klass end |
Instance Method Details
#at(timestamp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
265 266 267 268 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 265 def at() @expected_options["at"] = matcher?() ? : .to_time.to_i self end |
#at_least(n) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
310 311 312 313 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 310 def at_least(n) set_expected_count :at_least, n self end |
#at_most(n) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
315 316 317 318 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 315 def at_most(n) set_expected_count :at_most, n self end |
#common_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
383 384 385 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 383 def "#{} #{} #{klass} #{expected_count.last == 1 ? "job" : "jobs"}" end |
#description ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
345 346 347 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 345 def description "#{} with arguments #{expected_arguments}" end |
#exactly(n) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
305 306 307 308 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 305 def exactly(n) set_expected_count :exactly, n self end |
#failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 349 def = ["expected to #{}"] if expected_arguments << " with arguments:" << " -#{formatted(expected_arguments)}" end if .any? << " with context:" << " -#{formatted()}" end if actual_jobs.any? << "but enqueued only jobs" if expected_arguments = actual_jobs.map do |job| base = [" -JID:#{job.jid} with arguments:"] base << " -#{formatted(job.args)}" if .any? base << " with context: #{formatted(job.context)}" end base.join("\n") end << .join("\n") end else << "but enqueued 0 jobs" end .join("\n") end |
#failure_message_when_negated ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
391 392 393 394 395 396 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 391 def = ["expected not to #{} but enqueued #{actual_jobs.count}"] << " arguments: #{expected_arguments}" if expected_arguments.any? << " options: #{}" if .any? .join("\n") end |
#formatted(thing) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
398 399 400 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 398 def formatted(thing) RSpec::Support::ObjectFormatter.format(thing) end |
#immediately ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
275 276 277 278 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 275 def immediately @expected_options["at"] = nil self end |
#in(interval) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
270 271 272 273 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 270 def in(interval) @expected_options["at"] = matcher?(interval) ? interval : (Time.now.to_f + interval.to_f).to_i self end |
#never ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
285 286 287 288 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 285 def never set_expected_count :exactly, 0 self end |
#on(queue) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
280 281 282 283 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 280 def on(queue) @expected_options["queue"] = normalize_arguments(queue) self end |
#once ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
290 291 292 293 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 290 def once set_expected_count :exactly, 1 self end |
#prefix_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
387 388 389 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 387 def raise NotImplementedError end |
#thrice ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
300 301 302 303 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 300 def thrice set_expected_count :exactly, 3 self end |
#times ⇒ Object Also known as: time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
320 321 322 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 320 def times self end |
#twice ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
295 296 297 298 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 295 def twice set_expected_count :exactly, 2 self end |
#with(*expected_arguments) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
260 261 262 263 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 260 def with(*expected_arguments) @expected_arguments = normalize_arguments(expected_arguments) self end |
#with_context(**kwargs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 325 def with_context(**kwargs) raise ArgumentError, "Must specify keyword arguments to with_context" if kwargs.empty? # gather keys and compare against currently set expected_options # Someone could have accidentally used with_context and other # chainables with different expectations. Better to explicitly # inform loudly of clashes than let them overwrite silently normalized = normalize_arguments(kwargs) already_set = normalized.keys & @expected_options.keys if already_set.any? prettied = already_set.map { |key| "'#{key}'" } raise ArgumentError, "There are already expectations against #{prettied.join(",")}. Did you already call other context chainables like `on` or `at`?" end # We're good, no accidental overwrites of expectations @expected_options.merge!(normalized) self end |