Skip to content

Commit

Permalink
Address `Passing only keyword arguments to Struct#initialize will beh…
Browse files Browse the repository at this point in the history
…ave differently from Ruby 3.2.`

This commit addresses this warnings.

```ruby
$ ruby -v
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
$ bin/test test/template/template_test.rb:335
Running 46 tests in a single process (parallelization threshold is 50)
Run options: --seed 57841

/home/yahonda/src/github.com/rails/rails/actionview/test/template/template_test.rb:335: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).
E

Error:
TestERBTemplate#test_template_translate_location:
ActiveSupport::RaiseWarnings::WarningError: /home/yahonda/src/github.com/rails/rails/actionview/test/template/template_test.rb:335: warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/strict_warnings.rb:38:in `warn'
    test/template/template_test.rb:335:in `initialize'
    test/template/template_test.rb:335:in `new'
    test/template/template_test.rb:335:in `test_template_translate_location'

bin/test test/template/template_test.rb:330

Finished in 0.049434s, 20.2292 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
```

Follow up rails@f0afd24
  • Loading branch information
yahonda committed Nov 29, 2024
1 parent f0afd24 commit 001cc5d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions actionview/test/template/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_template_translate_location
source = "<%= nomethoderror %>"
compiled = "'.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -345,7 +345,7 @@ def test_template_translate_location_lineno_offset
source = "<%= nomethoderror %>"
compiled = "'.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight, first_lineno: 2, last_lineno: 2)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -361,7 +361,7 @@ def test_template_translate_location_with_multiline_code_source
compiled = "ValidatedOutputBuffer.wrap(@output_buffer, ({}), ' \ngood(\n nomethoderror\n" \
") '.freeze, true).safe_none_append=( \ngood(\n nomethoderror\n) );\n@output_buffer"

backtrace_location = Struct.new(:lineno).new(lineno: 6)
backtrace_location = Struct.new(:lineno).new(6)
spot = spot_highlight(compiled, highlight, first_column: 1, first_lineno: 6, last_lineno: 6, snippet: extracted_line)

assert_equal spot, new_template(source).translate_location(backtrace_location, spot)
Expand All @@ -372,7 +372,7 @@ def test_template_translate_location_with_multibye_string_before_highlight
source = String.new("\u{a5}<%= nomethoderror %>", encoding: Encoding::UTF_8) # yen symbol
compiled = String.new("\u{a5}'.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n", encoding: Encoding::UTF_8)

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -384,7 +384,7 @@ def test_template_translate_location_no_match_in_compiled
source = "<%= nomatch %>"
compiled = "this source does not contain the highlight, so the original spot is returned"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight, first_column: 50)

assert_equal spot, new_template(source).translate_location(backtrace_location, spot)
Expand All @@ -395,7 +395,7 @@ def test_template_translate_location_text_includes_highlight
source = " nomethoderror <%= nomethoderror %>"
compiled = " nomethoderror '.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -407,7 +407,7 @@ def test_template_translate_location_space_separated_erb_tags
source = "<%= goodcode %> <%= nomethoderror %>"
compiled = "'.freeze; @output_buffer.append= goodcode ; @output_buffer.safe_append=' '.freeze; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -419,7 +419,7 @@ def test_template_translate_location_consecutive_erb_tags
source = "<%= goodcode %><%= nomethoderror %>"
compiled = "'.freeze; @output_buffer.append= goodcode ; @output_buffer.append= nomethoderror ; @output_buffer.safe_append='\n"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -431,7 +431,7 @@ def test_template_translate_location_repeated_highlight_in_compiled_template
source = "<%= nomethoderror %>"
compiled = "ValidatedOutputBuffer.wrap(@output_buffer, ({}), ' nomethoderror '.freeze, true).safe_none_append= nomethoderror ; @output_buffer.safe_append='\n"

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand All @@ -443,7 +443,7 @@ def test_template_translate_location_flaky_pathological_template
source = "<%= flakymethod %> flakymethod <%= flakymethod " # fails on second call, no tailing %>
compiled = "ValidatedOutputBuffer.wrap(@output_buffer, ({}), ' flakymethod '.freeze, true).safe_none_append=( flakymethod );@output_buffer.safe_append=' flakymethod '.freeze;ValidatedOutputBuffer.wrap(@output_buffer, ({}), ' flakymethod '.freeze, true).safe_none_append=( flakymethod "

backtrace_location = Struct.new(:lineno).new(lineno: 1)
backtrace_location = Struct.new(:lineno).new(1)
spot = spot_highlight(compiled, highlight)
expected = spot_highlight(source, highlight, snippet: compiled)

Expand Down

0 comments on commit 001cc5d

Please sign in to comment.