Skip to content

Commit 422ce1b

Browse files
authored
Merge pull request rails#53310 from Shopify/3.4.0-preview2-actionview-prism
Skip Action View error mapping tests on 3.4+
2 parents 4b63c65 + 4add1ad commit 422ce1b

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

actionpack/test/support/rack_parsing_override.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ module RequestPatch
3535
def self.permitted_caller?
3636
caller_locations.any? do |loc|
3737
# Our parser calls Rack's to prepopulate caches
38-
loc.path.end_with?("lib/action_dispatch/http/request.rb") && loc.label == "request_parameters_list" ||
38+
loc.path.end_with?("lib/action_dispatch/http/request.rb") && loc.base_label == "request_parameters_list" ||
3939
# and as a fallback for older Rack versions
40-
loc.path.end_with?("lib/action_dispatch/http/request.rb") && loc.label == "fallback_request_parameters" ||
40+
loc.path.end_with?("lib/action_dispatch/http/request.rb") && loc.base_label == "fallback_request_parameters" ||
4141
# This specifically tests that a "pure" Rack middleware
4242
# doesn't interfere with our parsing
43-
(loc.path.end_with?("test/dispatch/request/query_string_parsing_test.rb") && loc.label == "populate_rack_cache") ||
43+
(loc.path.end_with?("test/dispatch/request/query_string_parsing_test.rb") && loc.base_label == "populate_rack_cache") ||
4444
# Rack::MethodOverride obviously uses Rack's parsing, and
4545
# that's fine: it's looking for a simple top-level key.
4646
# Checking for a specific internal method is fragile, but we
4747
# don't want to ignore any app that happens to have
4848
# MethodOverride on its call stack!
49-
(loc.path.end_with?("lib/rack/method_override.rb") && loc.label == "method_override_param")
49+
(loc.path.end_with?("lib/rack/method_override.rb") && loc.base_label == "method_override_param")
5050
end
5151
end
5252

actionview/lib/action_view/template.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def locals
228228
end
229229
end
230230

231+
SOURCE_MAPPING_SUPPORTED = RUBY_VERSION < "3.4" # https://github.com/rails/rails/issues/52902
232+
231233
def spot(location) # :nodoc:
232234
ast = RubyVM::AbstractSyntaxTree.parse(compiled_source, keep_script_lines: true)
233235
node_id = RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location(location)

actionview/test/template/render_test.rb

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -209,43 +209,51 @@ def test_render_outside_path
209209
end
210210
end
211211

212-
def test_render_runtime_error
213-
ex = assert_raises(ActionView::Template::Error) {
214-
@view.render(template: "test/runtime_error")
215-
}
216-
erb_btl = ex.backtrace_locations.first
212+
if ActionView::Template::SOURCE_MAPPING_SUPPORTED
213+
def test_render_template_with_syntax_error
214+
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/syntax_error") }
215+
assert_match %r!syntax!, e.message
216+
assert_equal "1: <%= foo(", e.annotated_source_code[0].strip
217+
end
217218

218-
# Get the spot information from ErrorHighlight
219-
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
220-
translated_spot = translating_frame.spot(ex.cause)
219+
def test_render_runtime_error
220+
ex = assert_raises(ActionView::Template::Error) {
221+
@view.render(template: "test/runtime_error")
222+
}
223+
erb_btl = ex.backtrace_locations.first
221224

222-
assert_equal 6, translated_spot[:first_column]
223-
end
225+
# Get the spot information from ErrorHighlight
226+
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
227+
translated_spot = translating_frame.spot(ex.cause)
224228

225-
def test_render_location_conditional_append
226-
ex = assert_raises(ActionView::Template::Error) {
227-
@view.render(template: "test/unparseable_runtime_error")
228-
}
229-
erb_btl = ex.backtrace_locations.first
229+
assert_equal 6, translated_spot[:first_column]
230+
end
230231

231-
# Get the spot information from ErrorHighlight
232-
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
233-
translated_spot = translating_frame.spot(ex.cause)
232+
def test_render_location_conditional_append
233+
ex = assert_raises(ActionView::Template::Error) {
234+
@view.render(template: "test/unparseable_runtime_error")
235+
}
236+
erb_btl = ex.backtrace_locations.first
234237

235-
assert_equal 8, translated_spot[:first_column]
236-
end
238+
# Get the spot information from ErrorHighlight
239+
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
240+
translated_spot = translating_frame.spot(ex.cause)
237241

238-
def test_render_location_conditional_append_2
239-
ex = assert_raises(ActionView::Template::Error) {
240-
@view.render(template: "test/unparseable_runtime_error_2")
241-
}
242-
erb_btl = ex.backtrace_locations.first
242+
assert_equal 8, translated_spot[:first_column]
243+
end
243244

244-
# Get the spot information from ErrorHighlight
245-
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
246-
translated_spot = translating_frame.spot(ex.cause)
245+
def test_render_location_conditional_append_2
246+
ex = assert_raises(ActionView::Template::Error) {
247+
@view.render(template: "test/unparseable_runtime_error_2")
248+
}
249+
erb_btl = ex.backtrace_locations.first
247250

248-
assert_instance_of Integer, translated_spot[:first_column]
251+
# Get the spot information from ErrorHighlight
252+
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
253+
translated_spot = translating_frame.spot(ex.cause)
254+
255+
assert_instance_of Integer, translated_spot[:first_column]
256+
end
249257
end
250258

251259
def test_render_partial
@@ -346,12 +354,6 @@ def test_render_partial_with_hyphen_and_invalid_option_as
346354
"and is followed by any combination of letters, numbers and underscores.", e.message
347355
end
348356

349-
def test_render_template_with_syntax_error
350-
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/syntax_error") }
351-
assert_match %r!syntax!, e.message
352-
assert_equal "1: <%= foo(", e.annotated_source_code[0].strip
353-
end
354-
355357
def test_render_partial_with_errors
356358
e = assert_raises(ActionView::Template::Error) { @view.render(partial: "test/raise") }
357359
assert_match %r!method.*doesnt_exist!, e.message

0 commit comments

Comments
 (0)