RSpec View testing: How to modify params?

后端 未结 4 597
清歌不尽
清歌不尽 2020-12-31 07:31

I am trying to test my views with RSpec. The particular view that is causing me troubles changes its appearance depending on a url parameter:

link_to \"sort>

4条回答
  •  -上瘾入骨i
    2020-12-31 07:49

    That's because you shouldn't be using params in your views.
    The best way I see it to use an helper.

    Sorted by <%= sorted_by %>

    And in one of your helper files

    def sorted_by
        params[:sorted_by].capitalize
    end
    

    Then you can test your helpers quite easily (because in helpers tests, you can define the params request.

提交回复
热议问题