0

我想创建一个可以向 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

我的gem的目录是:

在此处输入图像描述

错误是

NameError: undefined local variable or method `sharp_assets' for #<SharpAssetsTest:0x007ffe3c5abf08>
4

1 回答 1

1

您是否在 test_helper.rb 中需要您的库?

于 2013-01-22T11:08:07.513 回答