diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-12-26 23:04:46 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-02-14 12:02:07 +0900 |
commit | 45f0e3a673964069a4c9c57ce8665cbc21ac267f (patch) | |
tree | 9045469a13bc02380afd2a3109d48f3a5d289368 /test/ruby | |
parent | dbe5b0dcfffbad5a0ce3af1570dbb6db70266275 (diff) | |
download | ruby-45f0e3a673964069a4c9c57ce8665cbc21ac267f.tar.gz |
[Bug #19259] `Data#with` should call `initialize` method
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_data.rb | 16 |
1 files changed, 16 insertions, 0 deletions
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 |