gucki
gucki

Reputation: 4762

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


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

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.

Upvotes: 3

Views: 645

Answers (1)

Jules Copeland
Jules Copeland

Reputation: 1722

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

Upvotes: 1

Related Questions