Railsにいくつかのヘルパーメソッドを追加できるgemを作成したい:
module SharpAssets
class Railtie < Rails::Railtie
initializer "my_railtie.configure_rails_initialization" do |app|
app.middleware.use ::ActionDispatch::Static, "public"
ActionView::Base.send :include, ViewHelpers
end
config.to_prepare do
ActionView::Helpers.class_eval do
#ActionView::Base.send :include, SharpAssets::ViewHelpers
end
end
end
module ViewHelpers
#include Generators::Pagedown
puts "initializer my_railtie.configure_rails_initialization"
def sharp_assets
"sharp_assets"
end
end
end
私のテストケースは次のとおりです。
require 'test_helper'
class SharpAssetsTest < ActionView::TestCase
test "pagedown_tag be html safe" do
assert sharp_assets, ""
end
end
私のtest_helperは次のとおりです。
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end
私の宝石のディレクトリは次のとおりです。
エラーは
NameError: undefined local variable or method `sharp_assets' for #<SharpAssetsTest:0x007ffe3c5abf08>