Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to gems derived from Rails 7 causes Minitest errors #55

Open
benjaminoakes opened this issue Nov 7, 2023 · 0 comments
Open
Labels
bug Something isn't working dependencies Pull requests that update a dependency file help wanted Extra attention is needed

Comments

@benjaminoakes
Copy link
Contributor

benjaminoakes commented Nov 7, 2023

Background

While upgrading gems derived from Rails to address security vulnerabilities in #54, a series of spec errors prevented a normal bundle update. There was not an obvious fix to make the specs work on Rails 7, so I opted to force Rails 6 to resolve the security alerts. Please see "Technical Details" for more information.

Proposed

Upgrade all Rails-derived gems to version 7.x and fix any errors such that the test suite passes.

Technical Details

Using bundle update brought the Rails-derived gems to version 7.1.1 but this introduced unexpected spec failures, likely due to a dependency issue relating to the assert method. Both failing specs use perform_enqueued_jobs.

Debugging Notes

The following are my debugging notes in the hopes that they're useful to anyone working on this issue.

Details...

When running rake, the following specs failed:

  1) Integration can backfill using an example job
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

     NameError:
       uninitialized constant ActiveSupport::Testing::Assertions::Minitest
     # ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./spec/support/log_spec_helper.rb:11:in `capture_log'
     # ./spec/integration/backfill_spec.rb:49:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:62:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using an example job" (./spec/integration/backfill_spec.rb:11)>
     #   ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'

  2) Integration can backfill using a manually-set initial_id
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

     NameError:
       uninitialized constant ActiveSupport::Testing::Assertions::Minitest
     # ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:62:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using a manually-set initial_id" (./spec/integration/backfill_spec.rb:64)>
     #   ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'

It appears that Minitest may have been a "soft" dependency of ActiveJob::TestHelper or ActiveSupport::Testing::Assertions, as assert is referred to but never defined. Manually requiring minitest and adding config.include Minitest::Assertions partially resolves the error, but causes another:

  1) Integration can backfill using an example job
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

     NameError:
       undefined local variable or method `tagged_logger' for #<RSpec::ExampleGroups::Integration "can backfill using an example job" (./spec/integr
ation/backfill_spec.rb:11)>
     # ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./spec/support/log_spec_helper.rb:11:in `capture_log'
     # ./spec/integration/backfill_spec.rb:49:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:63:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using an example job" (./spec/integration/backfill_spec.rb:11)>
     #   ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'

  2) Integration can backfill using a manually-set initial_id
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

     NameError:
       undefined local variable or method `tagged_logger' for #<RSpec::ExampleGroups::Integration "can backfill using a manually-set initial_id" (./
spec/integration/backfill_spec.rb:64)>
     # ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:63:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using a manually-set initial_id" (./spec/integration/backfill_spec.rb:64)>
     #   ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'

I manually defined a tagged_logger:

def tagged_logger
  fake_log_device = StringIO.new

  ActiveSupport::TaggedLogging.new(Logger.new(fake_log_device))
end

...but that revealed even more errors:

  1) Integration can backfill using an example job
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

       `name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `l
et`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
     # ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./spec/support/log_spec_helper.rb:11:in `capture_log'
     # ./spec/integration/backfill_spec.rb:49:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:63:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using an example job" (./spec/integration/backfill_spec.rb:11)>
     #   ./spec/integration/backfill_spec.rb:50:in `block (3 levels) in <top (required)>'

  2) Integration can backfill using a manually-set initial_id
     Failure/Error:
       perform_enqueued_jobs do
         SuperSpreader::SchedulerJob.perform_now
       end

       `name` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `l
et`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
     # ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:63:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `assert' for #<RSpec::ExampleGroups::Integration "can backfill using a manually-set initial_id" (./spec/integration/backfill_spec.rb:64)>
     #   ./spec/integration/backfill_spec.rb:101:in `block (2 levels) in <top (required)>'

I stopped and instead manually defined assert:

  def assert(boolean)
    raise unless boolean
  end

This caused the specs to pass, which resolved my concern about Rails 7.x support. However, it doesn't explain the root cause, so I opted to force Rails 6.x in fe9ffa5.

See also

Related to: #17

@benjaminoakes benjaminoakes added bug Something isn't working help wanted Extra attention is needed dependencies Pull requests that update a dependency file labels Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant