Welcome to another edition of This Week in #dev, a series of posts where we bring some of the most interesting Slack conversations to the public. Today we’re talking about eliminating dead code, obsolete methods and mysterious test failures on newest Rails.
Summer ☀️ shares that
URI.escape was deprecated in Ruby 1.9.2 but
popular gems were still using it. However, ten years later in Ruby 3.0, it was
finally removed. This can often cause errors in Ruby 2→3 upgrades.
If you upgrade to latest Rails, Sean Doyle says, you might see errors similar to these in your tests:
expected to find text "can't be blank" in "Validate\nSubject can’t be blank Content Create Message"
Mike Burns’ advice here is to prevent this errors altogether by using using i18n helpers in tests to avoid asserting on bare strings:
# Expect a specific type of validation error for an attribute, such as :blank expect(model.errors).to be_added(:name, :error_type) expect(model.errors).to be_of_kind(:name, :error_type) # Expect any validation error for an attribute expect(model.errors).to include(:name) expect(model.errors).to have_key(:name)