Testing rendering of a given layout with RSpec & Rails

后端 未结 11 1383
滥情空心
滥情空心 2020-12-24 12:31

Is it possible to test the use of a given layout using RSpec with Rails, for example I\'d like a matcher that does the following:

response.should use_layout(         


        
11条回答
  •  囚心锁ツ
    2020-12-24 12:56

    Shoulda Matchers provides a matcher for this scenario. (Documentation) This seems to work:

           expect(response).to render_with_layout('my_layout')
    

    it produces appropriate failure messages like:

    Expected to render with the "calendar_layout" layout, but rendered with "application", "application"

    Tested with rails 4.2, rspec 3.3 and shoulda-matchers 2.8.0

    Edit: shoulda-matchers provides this method. Shoulda::Matchers::ActionController::RenderWithLayoutMatcher

提交回复
热议问题