How to call an app helper method from an RSpec test in Rails?

前端 未结 6 2003
太阳男子
太阳男子 2021-02-05 02:56

The title is self explanatory.

Everything I\'ve tried led to a \"undefined method\".

To clarify, I am not trying to test a helper method. I am trying to use a he

6条回答
  •  长情又很酷
    2021-02-05 03:18

    For anyone coming late to this question, it is answered on the Relish site.

    require "spec_helper"
    
    describe "items/search.html.haml" do
      before do
        controller.singleton_class.class_eval do
          protected
          def current_user
            FactoryGirl.build_stubbed(:merchant)
          end
          helper_method :current_user
        end
      end
    
      it "renders the not found message when @items is empty" do
        render
    
        expect(
          rendered
        ).to match("Sorry, we can't find any items matching "".")
      end
    end
    

提交回复
热议问题