开发者

spec view helper in gem

I'm writing a rails 3 railtie which defines some view helpers. Now I wonder how to spec the view helper methods because I cannot instantiate a module. I already searched and read a lot, but I just couldnt get it working.

view_helper_spec.rb


re开发者_StackOverflow社区quire '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

It always complains that "helper" is not defined. It seems that :type => :helper doesn't to anything.

The gemspec requires the rspec and the rspec-rails gems in development/ test mode.


I think I found the solution (it's painfully obvious once you think about it). Just stick this at the top of your spec:

require 'action_view'
require 'active_support'

include ViewHelper
include ActionView::Helpers
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜