ruby-on-rails – 如何测试我的控制器是否在Rails 3上呈现正确的布局?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何测试我的控制器是否在Rails 3上呈现正确的布局?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
控制器代码: @H_403_2@class BooksController < ApplicationController def index @books = Book.all respond_to do |format| format.html do render 'index',:layout => 'topgun' end end end end

如何在规范中测试?

@H_403_2@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调用的),看起来你应该能够做到

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

虽然我不完全确定会奏效.

猜你在找的Ruby相关文章