Adapt to ya_kansuji 1.3.0 fractional-number rendering - #33
Conversation
ya_kansuji 1.3.0 renders non-integer values (e.g. `to_kan(1.5, :simple)` => "一・五分") instead of truncating them as 1.2.0 did. Update the delegation spec to compute its expectation from YaKansuji.to_kan directly instead of hardcoding the old truncated output. This also surfaced a latent gap: Wareki::Date never type-checked year, so a non-integer year used to render silently truncated and now renders fractions in strftime output. Reject non-Integer years in _validate_date!, consistent with the existing Integer checks for month/day. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XJ7tz3UentFzdZEYpDcZbz
There was a problem hiding this comment.
Code Review
This pull request introduces validation to ensure that the year is an integer in Wareki::Date#_validate_date!, raising an InvalidDate exception otherwise. It also adds corresponding test cases for non-integer years and updates a utility test expectation. The reviewer suggested expanding the test coverage to verify that setting a non-integer era_year also raises an InvalidDate exception when calculating the Julian day.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| d = described_class.new('平成', 31, 4, 30) | ||
| d.year = 2019.5 | ||
| expect { d.jd }.to raise_error(Wareki::InvalidDate) |
There was a problem hiding this comment.
d.year = 2019.5 のテストに加えて、d.era_year = 1.5 のように era_year に非整数を代入した場合も同様に jd 呼び出し時に Wareki::InvalidDate が発生することを検証するテストケースを追加すると、よりテストの網羅性が向上します。
d = described_class.new('平成', 31, 4, 30)
d.year = 2019.5
expect { d.jd }.to raise_error(Wareki::InvalidDate)
d = described_class.new('平成', 31, 4, 30)
d.era_year = 1.5
expect { d.jd }.to raise_error(Wareki::InvalidDate)
概要
ya_kansuji 1.3.0 が小数対応し、
to_kan(1.5, :simple)が従来の切り捨て ("一") ではなく"一・五分"を返すようになったため、CI が失敗していました (例)。本 PR で以下の 2 点に対処します。1. spec の期待値をバージョン非依存に (
spec/utils_spec.rb)「非整数値の委譲」を検証する example が旧挙動の描画結果
'一'をハードコードしていたため、隣接する example と同様にYaKansuji.to_kan(1.5, :simple)から期待値を算出するよう変更。ya_kansuji のどのバージョンでもパスします。2.
Wareki::Dateの非整数 year を拒否 (lib/wareki/date.rb)year は month/day と異なり
_validate_date!で型チェックされておらず、Wareki::Date.new('平成', 1.5)のような非整数年は従来「暗黙の切り捨て描画」、ya_kansuji 1.3.0 では小数描画 (%JF→平成一・五分年一月一日) と、gem のバージョンで挙動が変わる状態でした。month/day の既存 Integer チェックと同様にWareki::InvalidDateを raise するようにします (整数値の Rational も month 同様拒否)。バリデーションのタイミングも既存と同じ initialize 時 + jd 変換時 (setter は遅延) です。なお、パース方向 (
YaKansuji.to_i) は 1.3.0 で無変更であり、wareki の捕捉文字クラスに小数単位が含まれないことも確認済みのため、変更は上記のみです。テスト
bundle exec rspec→ 103 examples, 0 failures (変更前は 1 failure)🤖 Generated with Claude Code
https://claude.ai/code/session_01XJ7tz3UentFzdZEYpDcZbz