From 45f0e3a673964069a4c9c57ce8665cbc21ac267f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 26 Dec 2022 23:04:46 +0900 Subject: [Bug #19259] `Data#with` should call `initialize` method --- test/ruby/test_data.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_data.rb b/test/ruby/test_data.rb index 3cafb365ed..9380076e1b 100644 --- a/test/ruby/test_data.rb +++ b/test/ruby/test_data.rb @@ -217,6 +217,22 @@ class TestData < Test::Unit::TestCase end end + def test_with_initialize + oddclass = Data.define(:odd) do + def initialize(odd:) + raise ArgumentError, "Not odd" unless odd.odd? + super(odd: odd) + end + end + assert_raise_with_message(ArgumentError, "Not odd") { + oddclass.new(odd: 0) + } + odd = oddclass.new(odd: 1) + assert_raise_with_message(ArgumentError, "Not odd") { + odd.with(odd: 2) + } + end + def test_memberless klass = Data.define -- cgit v1.2.3