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

Provide Rails-specific tools, possibly as a wrapper around Rails commands #248

Open
mmenanno opened this issue Nov 4, 2023 · 2 comments

Comments

@mmenanno
Copy link

mmenanno commented Nov 4, 2023

This is a follow up to #245. While the stringio issue seems to be resolved, something recursive seems to still be happening with the toys minitest integration loading.

If we use the same minimal replication setup:

rails new test_application 
cd test_appliction
bundle add toys

Then I creating a .toys.rb with this as the content:

expand :minitest, files: ["test/**/*_test.rb"], libs: ["test", "lib"]

Running rake test works as expected but toys test shows this warning:
/Users/username/.gem/ruby/3.2.2/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:8: warning: method redefined; discarding old require

To show the other example that is still happening here with this loading if you run bundle add bugsnag.

Then again running rake test works as expected but toys test shows this warning:

<internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37: warning: <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37: warning: loading in progress, circular require considered harmful - /Users/username/.gem/ruby/3.2.2/gems/bugsnag-6.26.0/lib/bugsnag.rb
        from -e:1:in  `<main>'
        from -e:1:in  `load'
        from test/channels/application_cable/connection_test.rb:1:in  `<top (required)>'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in  `require'
        from /Users/username/dev/git/test/test_application/test/test_helper.rb:2:in  `<top (required)>'
        from /Users/username/dev/git/test/test_application/test/test_helper.rb:2:in  `require_relative'
        from /Users/username/dev/git/test/test_application/config/environment.rb:2:in  `<top (required)>'
        from /Users/username/dev/git/test/test_application/config/environment.rb:2:in  `require_relative'
        from /Users/username/dev/git/test/test_application/config/application.rb:7:in  `<top (required)>'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler.rb:187:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler/runtime.rb:44:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler/runtime.rb:44:in  `each'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler/runtime.rb:55:in  `block in require'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler/runtime.rb:55:in  `each'
        from /Users/username/.gem/ruby/3.2.2/gems/bundler-2.4.21/lib/bundler/runtime.rb:60:in  `block (2 levels) in require'
        from /Users/username/.gem/ruby/3.2.2/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bugsnag-6.26.0/lib/bugsnag.rb:579:in  `<main>'
        from /Users/username/.gem/ruby/3.2.2/gems/bugsnag-6.26.0/lib/bugsnag.rb:251:in  `load_integrations'
        from /Users/username/.gem/ruby/3.2.2/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bugsnag-6.26.0/lib/bugsnag/integrations/railtie.rb:5:in  `<main>'
        from /Users/username/.gem/ruby/3.2.2/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in  `require'
        from /Users/username/.gem/ruby/3.2.2/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
        from <internal:/Users/username/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in  `require'
@dazuma
Copy link
Owner

dazuma commented Nov 5, 2023

Hi, thanks for continuing to poke at this!

I did a bit more digging here. It looks like just running minitest the normal way without either Toys or Rake will yield the same result:

▶ ruby -w -Ilib:test test/**/*.rb
/Users/dazuma/opt/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:8: warning: method redefined; discarding old require
Running 0 tests in a single process (parallelization threshold is 50)
Run options: --seed 30618

# Running:



Finished in 0.000649s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips

So it seems Rails really wants tests to be run via its own test runner (via the rails test command, which I believe the rake task invokes), instead of the normal minitest way.

Toys hasn't done any "native" integration with Rails yet; e.g. it doesn't know how to invoke the Rails command to run tests. I agree it would be a good idea to do provide Rails integration; I'll look into that for the next significant version. For now, if these warnings are causing issues, you can do one of the following:

  • Turn off Ruby warnings. The Toys minitest template activates Ruby warnings by default because it's good practice to check for warnings in your tests, but you can disable it by setting warnings: false, e.g.

    expand :minitest, files: ["test/**/*_test.rb"], libs: ["test", "lib"], warnings: false
    
  • Instead of creating test tools directly, use the rake template to wrap all the Rails rake tasks in tools. Remove the expand :minitest ... and instead just include:

    expand :rake
    

    That will create tools for all the normal rake tasks you'll get in a Rails app. e.g. in addition to toys test, you can toys db migrate, toys assets precompile, etc. The tools will actually just turn around and call rake; it's really just intended as a stopgap while you migrate rake tasks to Toys tools, but it should work for this case.

@mmenanno
Copy link
Author

mmenanno commented Nov 5, 2023

Amazing, thanks for looking into this and all your hard work on toys! I look forward to a future rails integration in the future and will use one of the suggested workarounds for now!

@dazuma dazuma changed the title Built in minitest integration recursively loading Provide Rails-specific tools, possibly as a wrapper around Rails commands Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants