toshimaru/jekyll-toc

rake test fails with ruby3.2

mtasaka opened this issue · 1 comments

With released ruby 3.2.0, $ rake test fails with jekyll-toc git head (currently: 359feb7) like:

$ rake test
/usr/bin/ruby -w -I"lib:lib:test" /usr/share/gems/gems/rake-13.0.6/lib/rake/rake_test_loader.rb "test/parser/test_inject_anchors_filter.rb" "test/parser/test_invalid_options.rb" "test/parser/test_ordered_list.rb" "test/parser/test_toc_filter.rb" "test/parser/test_toc_only_filter.rb" "test/parser/test_various_toc_html.rb" "test/test_configuration.rb" "test/test_helper.rb" "test/test_jekyll-toc.rb" "test/test_kramdown_list.rb" "test/test_toc_tag.rb" s/gems/nokogiri-1.13.10/lib/nokogiri/version/info.rb:76: warning: statement not reached
Started with run options --seed 16027


ERROR TestTableOfContentsFilter#test_toc2 (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page, site
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `enable_toc_context'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:36:in `test_toc2'

ERROR TestTableOfContentsFilter#test_inject_anchors2 (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page, site
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `enable_toc_context'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:31:in `test_inject_anchors2'

ERROR TestTableOfContentsFilter#test_inject_anchors (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `disable_toc_context'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:16:in `test_inject_anchors'

ERROR TestTableOfContentsFilter#test_toc (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `disable_toc_context'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:21:in `test_toc'

ERROR TestTableOfContentsFilter#test_toc_only2 (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page, site
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:47:in `enable_toc_context'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:26:in `test_toc_only2'

ERROR TestTableOfContentsFilter#test_toc_only (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:43:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_jekyll-toc.rb:11:in `test_toc_only'

ERROR TestTableOfContentsTag#test_toc_tag_returns_empty_string (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:24:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:24:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:24:in `test_toc_tag_returns_empty_string'

ERROR TestTableOfContentsTag#test_toc_tag (0.01s)
Minitest::UnexpectedError:         ArgumentError: unknown keywords: page, site
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:15:in `initialize'
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:15:in `new'
            /builddir/build/GIT/jekyll-toc/test/test_toc_tag.rb:15:in `test_toc_tag'

=======================================================================================================================================
....
....
Finished in 0.25292s
51 tests, 111 assertions, 0 failures, 8 errors, 0 skips
Coverage report generated for Unit Tests to /builddir/build/GIT/jekyll-toc/coverage. 367 / 389 LOC (94.34%) covered.
rake aborted!

This is because of "announced" Strcut behavior changed in ruby3.2 that "keyword_init" being true by default:

So passing keyword argument to Struct behaves differently in ruby3.2.

ruby3.1 actually already warns about this:

[tasaka1@localhost ~]$ ruby --version
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
[tasaka1@localhost ~]$ ruby -e "Struct.new(:registers).new(page: { 'toc' => false })"
-e:1: 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).
[tasaka1@localhost ~]$ ruby -e "Struct.new(:registers, keyword_init: true).new(page: { 'toc' => false })"
-e:1:in `initialize': unknown keywords: page (ArgumentError)
	from -e:1:in `new'
	from -e:1:in `<main>'