Class: RSpec::Sidekiq::Matchers::Base Private
- Inherits:
-
Object
- Object
- RSpec::Sidekiq::Matchers::Base
- Includes:
- Matchers::Composable, Mocks::ArgumentMatchers
- 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
- #count_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.
- #normalize_arguments(args) ⇒ Object private
- #on(queue) ⇒ Object private
- #once ⇒ Object private
- #prefix_message ⇒ Object private
- #set_expected_count(relativity, n) ⇒ Object private
- #thrice ⇒ Object private
- #times ⇒ Object (also: #time) private
- #twice ⇒ Object private
- #with(*expected_arguments) ⇒ 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.
180 181 182 183 184 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 180 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.
178 179 180 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 178 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.
178 179 180 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 178 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.
178 179 180 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 178 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.
178 179 180 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 178 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.
178 179 180 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 178 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.
191 192 193 194 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 191 def at() @expected_options["at"] = .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.
231 232 233 234 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 231 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.
236 237 238 239 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 236 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.
296 297 298 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 296 def "#{} #{} #{klass} #{expected_count.last == 1 ? "job" : "jobs"}" end |
#count_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.
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 304 def case expected_count in [:positive, _] "a" in [:exactly, n] n in [relativity, n] "#{relativity.to_s.gsub('_', ' ')} #{n}" end 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.
258 259 260 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 258 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.
226 227 228 229 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 226 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.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 262 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 << "\n -#{formatted(job.args)}" if .any? base << "\n with context: #{formatted(job.context)}" end base 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.
315 316 317 318 319 320 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 315 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.
322 323 324 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 322 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.
201 202 203 204 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 201 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.
196 197 198 199 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 196 def in(interval) @expected_options["at"] = (Time.now.to_f + interval.to_f).to_i self end |
#normalize_arguments(args) ⇒ 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.
326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 326 def normalize_arguments(args) if args.is_a?(Array) args.map{ |x| normalize_arguments(x) } elsif args.is_a?(Hash) args.each_with_object({}) do |(key, value), hash| hash[key.to_s] = normalize_arguments(value) end elsif args.is_a?(Symbol) args.to_s else args end 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.
206 207 208 209 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 206 def on(queue) @expected_options["queue"] = 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.
211 212 213 214 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 211 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.
300 301 302 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 300 def raise NotImplementedError end |
#set_expected_count(relativity, 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.
246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 246 def set_expected_count(relativity, n) n = case n when Integer then n when :once then 1 when :twice then 2 when :thrice then 3 else raise ArgumentError, "Unsupported #{n} in '#{relativity} #{n}'. Use either an Integer, :once, :twice, or :thrice." end @expected_count = [relativity, n] 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.
221 222 223 224 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 221 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.
241 242 243 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 241 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.
216 217 218 219 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 216 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.
186 187 188 189 |
# File 'lib/rspec/sidekiq/matchers/base.rb', line 186 def with(*expected_arguments) @expected_arguments = normalize_arguments(expected_arguments) self end |