3

私はいくつかのビューヘルパーを定義するrails3railtieを書いています。モジュールをインスタンス化できないため、ビューヘルパーメソッドをどのように指定するのか疑問に思います。私はすでにたくさん検索して読んでいますが、それを機能させることができませんでした。

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-railsgemが必要です。

4

1 に答える 1

1

解決策を見つけたと思います(考えてみれば、それは痛々しいほど明らかです)。これをスペックの一番上に貼り付けてください:

require 'action_view'
require 'active_support'

include ViewHelper
include ActionView::Helpers
于 2012-03-20T11:41:47.700 に答える