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

Frozen string literal issue with Rails 3.4+ (with solution) #119

Closed
ron-shinall opened this issue Feb 13, 2025 · 3 comments
Closed

Frozen string literal issue with Rails 3.4+ (with solution) #119

ron-shinall opened this issue Feb 13, 2025 · 3 comments

Comments

@ron-shinall
Copy link

ron-shinall commented Feb 13, 2025

I'm getting frozen-string-literal warnings with Ruby 3.4.1 from magic.rb line 120. I also have a potential solution, if indeed this is an issue...and I am happy to open a PR for review & feedback.

To recreate the issue, you can generate a minimal Rails app with the following (making sure to use Ruby 3.4+):

rails new marcel_scaffold --skip-git --skip-docker --skip-keeps --skip-asset-pipeline --skip-rubocop --skip-brakeman --skip-ci --skip-kamal --skip-devcontainer --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-javascript --skip-hotwire --skip-decrypted-diffs --skip-action-cable --skip-bootsnap --skip-dev-gems --skip-jbuilder --skip-system-test --skip-thruster

Then execute:

bin/rails active_storage:install
bin/rails db:migrate

And create & run a test like this:

require "test_helper"

class MarcelTest < ActiveSupport::TestCase
  test "mime type" do
    assert_not_empty Marcel::MimeType.for StringIO.new("foo")
  end
end

You should see a warning as below:

Running 1 tests in a single process (parallelization threshold is 50)
Run options: --name "/MarcelTest(#|::)/" --seed 24608

# Running:

/path_to_gems/marcel-1.0.4/lib/marcel/magic.rb:120: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
.

Finished in 0.050929s, 19.6352 runs/s, 19.6352 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
@ron-shinall
Copy link
Author

@jeremy have you come across this? Please let me know if you need more information.

@jeremy
Copy link
Member

jeremy commented Feb 13, 2025

Haven't yet. Please do investigate!

@ron-shinall ron-shinall changed the title Frozen string literal issue with Rails 3.4+ (with potential solution) Frozen string literal issue with Rails 3.4+ (with solution) Feb 14, 2025
@ron-shinall
Copy link
Author

@jeremy ok, after more digging it turns out that it's the tests that are generating the "chilled" strings and therefore triggering the deprecation warning. Adding # frozen_string_literal: true to the test files resolved the issue for me.

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