3

我正在编写一个定义了一些视图助手的 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

它总是抱怨没有定义“助手”。似乎 :type => :helper 没有任何作用。

gemspec 在开发/测试模式下需要 rspec 和 rspec-rails gem。

4

1 回答 1

1

我想我找到了解决方案(一旦你想到它就很明显了)。只需将其粘贴在规范的顶部即可:

require 'action_view'
require 'active_support'

include ViewHelper
include ActionView::Helpers
于 2012-03-20T11:41:47.700 回答