はじめに
hkob の雑記録の第456回目(通算29日目)は、View API の TitleProperty のテストを作成していきます。
title_property_spec.rb の修正
現在の title_property_spec.rb は以下のようになっています。
# frozen_string_literal: true module NotionRubyMapping RSpec.describe TitleProperty do tc = TestConnection.instance let(:no_content_json) { {"id" => "title"} } let(:first_page_id) { TestConnection::DB_FIRST_PAGE_ID } let(:property_cache_first) { PropertyCache.new base_type: "page", page_id: first_page_id } context "when Database property" do (Database property のテスト) end context "when DataSource property" do (DataSource property のテスト) end context "when Page property" do (Page property のテスト) end end
ここに View property のテストを追加していく形になります。DataSource のテストを参考に作成してみます。visible と wrap は無指定の場合には true が設定されるようにしてみます。
context "when View property" do context "when created by new" do let(:target) { described_class.new "tp", base_type: "view", view_options: {"width" => 100} } it_behaves_like "has name as", "tp" it_behaves_like "property view json", {"property_name" => "tp", "visible" => true, "wrap" => true, "width" => 100} it_behaves_like "assert different property", :property_values_json it_behaves_like "assert different property", :property_schema_json describe "width=" do before { target.width = 200 } it_behaves_like "will update" it_behaves_like "property view json", {"property_name" => "tp", "visible" => true, "wrap" => true, "width" => 200} end end context "when created from json" do let(:target) { Property.create_from_json "tp", tc.read_json("title_property_object"), "view" } it { expect(target.class).to eq Property } it_behaves_like "has name as", "tp" it_behaves_like "will not update" it_behaves_like "assert different property", :property_values_json it_behaves_like "update property schema json", {} end end
とここまでテストを書いたものの、property の実装を記述しているうちに共通部分があまりないことに気づきました。また、Property の種類ごとの変化もあまりないので、ViewProperty という特別なクラスを作成した方がいい気がしました。ここまでテストを書きましたが、このテストはキャンセルして、view_property_spec.rb としてやり直すことにします。
おわりに
途中まで記載してあまりいい実装でないことに気づくことはよくあります。これまではこういう記録はあまりしていなかったのですが、たまにはこういうのもあるかと思い、記録に残すことにしました(一週目の授業準備で忙しいという口実もあります)。取り急ぎ明日出直します。