How do I test whether my controller rendered the right layout on Rails 3?

前端 未结 2 1717
陌清茗
陌清茗 2021-01-04 00:31

Controller code:

class BooksController < ApplicationController
  def index
    @books = Book.all
    respond_to do |format|
      format.html do
        r         


        
2条回答
  •  甜味超标
    2021-01-04 00:46

    You may find the "Testing Controllers with RSpec" RailsCast and the official rspec-rails documentation helpful.

    Looking at the code for assert_template (which is just what render_template calls), it looks like you should be able to do

    response.should render_template("index")
    response.should render_template(:layout => "topgun")
    

    though I'm not entirely sure that will work.

提交回复
热议问题