gpt4 book ai didi

ruby-on-rails - 如何测试我的 Controller 是否在 Rails 3 上呈现了正确的布局?

转载 作者:行者123 更新时间:2023-12-03 14:01:01 25 4
gpt4 key购买 nike

Controller 代码:

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 , 但我的 response对象似乎没有 layout属性/方法。

最佳答案

您可以找到 "Testing Controllers with RSpec" RailsCast 和官方 rspec-rails documentation有帮助。

查看 assert_template 的代码(这正是 render_template 所调用的),看起来你应该能够做到

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

虽然我不完全确定这会奏效。

关于ruby-on-rails - 如何测试我的 Controller 是否在 Rails 3 上呈现了正确的布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4995042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com