Skip to content

Adapt to ya_kansuji 1.3.0 fractional-number rendering - #33

Merged
sugi merged 1 commit into
masterfrom
fix/ya-kansuji-1.3-fraction
Jul 18, 2026
Merged

Adapt to ya_kansuji 1.3.0 fractional-number rendering#33
sugi merged 1 commit into
masterfrom
fix/ya-kansuji-1.3-fraction

Conversation

@sugi

@sugi sugi commented Jul 18, 2026

Copy link
Copy Markdown
Owner

概要

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 の捕捉文字クラスに小数単位が含まれないことも確認済みのため、変更は上記のみです。

テスト

  • ya_kansuji 1.3.0 環境で bundle exec rspec → 103 examples, 0 failures (変更前は 1 failure)
  • rubocop: 新規 offense なし

🤖 Generated with Claude Code

https://claude.ai/code/session_01XJ7tz3UentFzdZEYpDcZbz

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread spec/date_spec.rb
Comment on lines +150 to +152
d = described_class.new('平成', 31, 4, 30)
d.year = 2019.5
expect { d.jd }.to raise_error(Wareki::InvalidDate)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 97.342% (+0.006%) from 97.336% — fix/ya-kansuji-1.3-fraction into master

@sugi
sugi merged commit 304fad7 into master Jul 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants