运行minitest时出错,期待但是渲染

问题描述 投票:1回答:1

测试此代码时出现故障...所述错误是“期待<”admin / dashboard“>但是使用<[]>进行渲染

集成测试页面代码片段是

require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
  def setup
    @admin = admins(:admn)
  end

  test "admin dashboard link" do
    get login_admin_path
    post login_admin_path, params: { session: { username: @admin.username,
                                          password: 'Ha66y@Air' } }        

    get admin_dashboard_path
    assert_template 'admin/dashboard'
 end
end 

route.rb中的代码片段是

get '/admin/dashboard', to: 'admin#dashboard'

登录控制器中的代码片段是

def create
    admin = Admin.find_by(username: params[:session][:username])
    if admin && admin.authenticate(params[:session][:password])
      # render 'admin/dashboard'
      log_in admin
      params[:session][:remember_me] == '1' ? remember(admin) : forget(admin)

      redirect_to admin_dashboard_path


    else
      render 'login/admin'
      flash.now[:danger] = 'Invalid email/password combination'
    end

  end

管理控制器中的代码段是

def dashboard
    redirect_to root_url unless logged_in?
    @admin = current_user
  end

admins.yml的代码片段是

admn:
  username: "adminm"
  password_digest: <%= Admin.digest('admin') %>

该应用程序在服务器中成功运行。但是,运行测试时会发生错误。

ruby-on-rails ruby-on-rails-5 integration-testing
1个回答
1
投票

redirect_to admin_dashboard_path不呈现模板,它呈现重定向命令; HTTP 302.然后浏览器立即获取指定的页面,这就是手动测试通过的原因。试试assert_redirected_to

© www.soinside.com 2019 - 2024. All rights reserved.