加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 20:16:44 所属栏目:百科 来源:网络整理
导读:控制器代码: class BooksController ApplicationController def index @books = Book.all respond_to do |format| format.html do render 'index',:layout = 'topgun' end end endend 如何在规范中测试? require 'spec_helper'describe BooksController do
控制器代码:
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")

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读