From 7dab169990b9e3164ef98881e3b84bf993148e65 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 7 Jun 2021 20:38:31 +0200 Subject: [PATCH] DEV: Fix a flaky Onceoff spec (#13314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error was: ``` Jobs::Onceoff can run all once off jobs without errors Failure/Error: j.new.execute_onceoff(nil) TypeError: can't create instance of singleton class # ./spec/integrity/onceoff_integrity_spec.rb:13:in `new' # ./spec/integrity/onceoff_integrity_spec.rb:13:in `block (3 levels) in
' # ./spec/integrity/onceoff_integrity_spec.rb:12:in `each' # ./spec/integrity/onceoff_integrity_spec.rb:12:in `block (2 levels) in
' # ./spec/rails_helper.rb:279:in `block (2 levels) in ' # ./bundle/ruby/2.7.0/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in `block (2 levels) in ' ``` Sometimes the class found by `ObjectSpace.each_object(Class)` would be e.g: `#>` …instead of e.g: `#` This commit changes the `#select` to filter out those classes. --- spec/integrity/onceoff_integrity_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/integrity/onceoff_integrity_spec.rb b/spec/integrity/onceoff_integrity_spec.rb index 7918995448f..3fe53bb9647 100644 --- a/spec/integrity/onceoff_integrity_spec.rb +++ b/spec/integrity/onceoff_integrity_spec.rb @@ -4,13 +4,13 @@ require "rails_helper" describe ::Jobs::Onceoff do it "can run all once off jobs without errors" do - # load all once offs - + # Load all once offs Dir[Rails.root + 'app/jobs/onceoff/*.rb'].each do |f| require_relative '../../app/jobs/onceoff/' + File.basename(f) end - ObjectSpace.each_object(Class).select { |klass| klass < ::Jobs::Onceoff }.each do |j| - j.new.execute_onceoff(nil) - end + + ObjectSpace.each_object(Class) + .select { |klass| klass.superclass == ::Jobs::Onceoff } + .each { |job| job.new.execute_onceoff(nil) } end end