控制器代码:
class BooksController < ApplicationController def index @books = Book.all respond_to do |format| format.html do render 'index',:layout => 'topgun' end end end end
如何在规范中测试?
require 'spec_helper' describe BooksController do describe "GET index" do it "renders the topgun layout" do get :index # ??? end end end
我检查了this related post,但我的响应对象似乎没有布局属性/方法.
解决方法
您可能会发现
“Testing Controllers with RSpec” RailsCast和官方
rspec-rails documentation有帮助.
看看assert_template
的代码(这是render_template
调用的),看起来你应该能够做到
response.should render_template("index") response.should render_template(:layout => "topgun")
虽然我不完全确定会奏效.