Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActionController::UnknownFormat:带有rspec和get请求(Rails5)_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails ActionController::UnknownFormat:带有rspec和get请求(Rails5)

Ruby on rails ActionController::UnknownFormat:带有rspec和get请求(Rails5),ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我试图在rails 5上使用rspec进行控制器测试,但在运行测试时,我总是会遇到“ActionController::UnknownFormat”异常 以下是错误消息: Failure/Error: get :index ActionController::UnknownFormat: MessagesController#index is missing a template for this request format and variant. request.for

我试图在rails 5上使用rspec进行控制器测试,但在运行测试时,我总是会遇到“ActionController::UnknownFormat”异常

以下是错误消息:

 Failure/Error: get :index

 ActionController::UnknownFormat:
   MessagesController#index is missing a template for this request format and variant.

   request.formats: ["text/html"]
   request.variant: []

 NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
以下是rspec代码:

require 'rails_helper'
describe MessagesController do
  describe 'GET #index' do
    it "renders the :index template" do
      get :index
      expect(response).to render_template :index
    end
  end
end
以下是控制器代码:

class MessagesController < ApplicationController
  def index
  end
我在views/messages/index.html.haml中创建了视图文件。 通常,我可以使用本地环境在web浏览器上查看视图文件。 但是,在rspec上,它找不到视图文件。我不明白

知道哪里出了问题吗?
我有麻烦了。请帮我看看响应对象,它可能会解释发生了什么。请在问题中添加该问题的打印内容。您是否已将
gem'rails controller testing'
添加到您的gem文件中?请查看响应对象,它可能会解释发生了什么。请在问题中添加该问题的打印件。您是否已将
gem'rails controller testing'
添加到您的gem文件中?
Rails.application.routes.draw do
  resources :messages, only: [:index]
end