[rspec-users] testing a render of a partial in a helper

nathanvda nathanvda at gmail.com
Wed Oct 5 15:28:57 EDT 2011


I am trying to spec my helpers, and I find a few of my helpers
actually render a partial.

My code:

    module PageHelper
      def settings_menu
        render :partial => '_shared/settings_menu'
      end

      def banner_for(model)
        banner_message = ... some message ...
        render :partial => 'shared/banner', :locals => { :message =>
banner_message }
      end
    end

I want to be able to either capture the result of the render, or just
express the expectation that the `render` is called. For now neither
work. My test now looks as follows:

    require 'spec_helper'

    describe PageHelper do

      context "settings_menu" do
        it "render the correct partial" do
          helper.should_receive(:render).with({:partial => 'shared/
settings_menu'})
          helper.settings_menu
        end
        it "generates the correct result" do
          @result = helper.settings_menu
          @result.should be == "something"
        end
      end
    end

Both of these tests fail. The expectation is never met, and `@result`
is always `nil`.


More information about the rspec-users mailing list