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

stringio redefined warnings #245

Closed
mmenanno opened this issue Oct 20, 2023 · 3 comments
Closed

stringio redefined warnings #245

mmenanno opened this issue Oct 20, 2023 · 3 comments

Comments

@mmenanno
Copy link

I was trying to narrow down an issue for something else and stumbled across some weird stringio conflicts again.

I did:

rails new test_application 
cd test_appliction
bundle add toys

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

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

When running rake test I have no issues, but if I run toys test I get:

/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: already initialized constant StringIO::VERSION
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old new
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old open
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old initialize
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old initialize_copy
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old reopen
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old string
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old string=
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old lineno
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old lineno=
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old binmode
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old close
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old close_read
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old close_write
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old closed?
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old closed_read?
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old closed_write?
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old eof
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old eof?
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old fcntl
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old flush
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old fsync
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old pos
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old pos=
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old rewind
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old seek
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old sync
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old sync=
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old tell
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old each
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old each_line
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old each_byte
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old each_char
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old each_codepoint
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old getc
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old ungetc
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old ungetbyte
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old getbyte
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old gets
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old readlines
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old read
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old write
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old putc
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old isatty
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old tty?
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old pid
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old fileno
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old size
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old length
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old truncate
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old external_encoding
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old internal_encoding
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old set_encoding
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old set_encoding_by_bom
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old readchar
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old readbyte
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old readline
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old sysread
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old readpartial
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old read_nonblock
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old <<
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old print
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old printf
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old puts
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old syswrite
/Users/username/.gem/ruby/3.2.2/gems/stringio-3.0.8/lib/stringio.bundle: warning: method redefined; discarding old write_nonblock
Running 0 tests in a single process (parallelization threshold is 50)
Run options: --seed 27806

# Running:



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

This is with the latest toys 0.15.2, ruby 3.2.2, and rails 7.1.1 on macOS Sonoma (14.0)

@dazuma
Copy link
Owner

dazuma commented Oct 21, 2023

Try removing toys from the bundle and see if that helps. Otherwise I'll take another look.

@dazuma
Copy link
Owner

dazuma commented Oct 26, 2023

I spent a few moments looking at this today. One workaround I found is to tell Toys to manage the bundle, rather than depending on Rails to do the bundle setup in boot.rb. You can do this by adding bundler: true to the minitest template expansion, i.e.

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

As for why we're getting the stringio issue with Rails, I haven't yet connected all the dots, but has something to do with Toys using stringio, then Rails loading a different version in its bundle. As with the other issue you filed, the root of the problem seems to be that Rubygems isn't recognizing stringio properly as a built-in gem, and is allowing multiple versions of it to load. For example, you can reproduce the issue without Toys, just by adding require "stringio" to the start of bin/rake and then running bin/rake test. I think, ultimately, we're going to have to open an issue against Rubygems for this. I'll look into it more when I have some time next week.

@dazuma
Copy link
Owner

dazuma commented Oct 31, 2023

I released a workaround in Toys 0.15.3. Turns out that Minitest itself was doin the initial pre-bundle loading of stringio, so I moved require "minitest" to the end of the script that Toys runs to invoke the tests.

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