Fix inefficient assert pattern in Rack::Lint [2-2-stable] #2101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partial backport of 1970771
Differences from original commit:
#assert
is not deprecatedinclude Assertion
is not removedcheck_status
is the 2-2-stable version since the SPEC change to require statuses to be integers was merged before this#dump
was added to theREQUEST_METHOD
assertion after the original commit, so it was added here as wellThis fixes an issue encountered when adding
Rack::Lint
to the Rails test suite. Rails puts a lazily evaluated class inside the request env that has the potential to raise when converted to a string. Since this assertion inRack::Lint
calls#inspect
onenv
whether or notenv
is aHash
, the lazily evaluated class would raise at that point and prevent the rest ofRack::Lint
from validating the conformity of the request.By backporting this change,
#inspect
is now only called when theLintError
would be raised which avoids the problem.I started with the smallest change needed to fix the problem in the Rails test suite, but I'm happy to add more based on feedback