開発環境の警告を解消するための依存関係とRubyバージョンの更新
ViewComponentのローカル開発環境で発生していた警告を解消するため、Rubyバージョンの更新と依存関係の明示的な追加が行われました。これにより、開発者が不要な警告メッセージに悩まされることなく、コンポーネント開発に集中できる環境が整いました。
背景
ローカル開発環境でテストを実行する際、minitest-mock が暗黙的に読み込まれていたものの、Gemfile に明示されていないことで警告が発生していました。また、to_time_preserves_timezone の設定に関する非推奨警告も発生していました。これらの警告は開発体験を損ねるものであり、#2544 でまとめて解消されています。
技術的な変更
本PRでは、3つの異なる種類の警告に対処するため、複数のファイルが更新されました。
Rubyバージョンの更新
.tool-versions でRubyバージョンが4.0.0から4.0.1に更新されました:
-ruby 4.0.0
+ruby 4.0.1
minitest-mockの明示的な追加
Gemfile の development および test グループに minitest-mock が追加されました:
group :development, :test do
gem "m", "~> 1"
gem "method_source", "~> 1"
gem "minitest", "~> 6"
gem "minitest-mock" # 追加
gem "nokogiri", "1.19.0"
# ...
end
test/test_helper.rb でも明示的な require が追加されています:
require "minitest/autorun"
require "minitest/mock" # 追加
これにより、minitest-mock への依存関係が明示され、暗黙的な読み込みによる警告が解消されます。
非推奨設定の削除
テスト環境の設定ファイル test/sandbox/config/environments/test.rb から、to_time_preserves_timezone の設定が削除されました:
config.eager_load = true
-
- config.active_support.to_time_preserves_timezone = :zone
end
この設定項目が非推奨となったため、明示的な設定を削除することで警告が解消されます。
テストコードのリファクタリング
test/sandbox/test/base_test.rb では、ActiveSupport::Configurable と ViewComponent::Configurable の混在による警告を解消するため、テストモジュールが整理されました:
変更前:
module TestAlreadyConfiguredModule
include ActiveSupport::Configurable
configure do |config|
config.view_component = ActiveSupport::InheritableOptions[instrumentation_enabled: false]
end
include ViewComponent::Configurable
class SomeComponent < ViewComponent::Base
end
end
変更後:
module TestAlreadyConfiguredModule
include ViewComponent::Configurable
configure do |config|
config.view_component = ActiveSupport::InheritableOptions[instrumentation_enabled: false]
end
class SomeComponent < ViewComponent::Base
end
end
ViewComponent::Configurable が内部で ActiveSupport::Configurable を既にインクルードしているため、重複したインクルードが削除されています。同様の変更が TestAlreadyConfigurableModule にも適用されました。
まとめ
本PRは、開発環境で発生していた複数の警告を解消する変更です。Rubyバージョンの更新、minitest-mock の明示的な追加、非推奨設定の削除、テストコードの整理により、クリーンな開発環境が維持されます。