1

学習のためだけにいくつかのヘルパー メソッドを追加するエンジンを作成します。

module SharpAssets
  class Engine < ::Rails::Engine
    initializer "sharp_asssets.assets_precompile" do |app|
      ActionView::Base.send(:include, SharpAssets::Helper)
    end
  end

  module Helper
    def hi_engine
      "test"
    end
  end
end

私のテストケースは次のとおりです。

require 'test_helper'

class SharpAssetsTest < ActionView::TestCase
  include SharpAssets::Helper  
  test "should work" do
    assert_equal "test", hi_engine
  end
end

私は知りたいのですが、この方法は良い習慣ですか?

もう 1 つの質問は、なぜSharpAssets::Helperテスト ケースに含めることができるのかということです。libフォルダーからのファイルは必要ありません。

4

0 に答える 0