thoughtbot / shoulda-matchers

Simple one-liner tests for common Rails functionality
https://matchers.shoulda.io
MIT License
3.51k stars 912 forks source link

The library doesn't work with frozen-string-literals enabled globally. #1563

Closed aliaksandrb closed 9 months ago

aliaksandrb commented 1 year ago

Hio!

The library using String modification in place in some places, for example:

  ''.tap do |preface|
    if descriptions_for_preset_values.any?
      preface << 'After setting '
      preface << descriptions_for_preset_values.to_sentence
      preface << ', then '
    else
      preface << 'After '
    end
. . .
end

So, when the application has frozen-string-literals enabled globally (instead of per-file "magic" comment) via:

ENV RUBYOPT='--enable=frozen-string-literal'

It raises an error when specs are executed:

 FrozenError:
   can't modify frozen String: ""
 # /usr/local/share/gems/gems/shoulda-matchers-5.3.0/lib/shoulda/matchers/active_model/allow_value_matcher.rb:550:in `block in default_failure_message_preface'

🥲

aliaksandrb commented 9 months ago

Yay, thanks! 🥳