宝石中的spec视图助手

问题描述

| 我正在编写定义一些视图助手的rails 3 railtie。现在,我想知道如何指定视图助手方法,因为我无法实例化模块。我已经搜索了很多东西,但是我无法使其正常工作。 view_helper_spec.rb
require \'spec_helper\'
module MyRailtie
  describe ViewHelper,:type => :helper do
    describe \"style_tag\" do
      it \"should return a style tag with inline css\" do
        helper.style_tag(\"body{background:#ff0}\").should == 
            body{background:#ff0}
          
        EOT
      end
    end
  end
end
它总是抱怨\“ helper \”没有定义。似乎:type =>:helper没有任何作用。 gemspec在开发/测试模式下需要rspec和rspec-rails gem。     

解决方法

我想我找到了解决方案(一旦您想到它,这显然很痛苦)。只需将其放在您的规格顶部即可:
require \'action_view\'
require \'active_support\'

include ViewHelper
include ActionView::Helpers