Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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 如何为仅呈现html的控制器方法编写rspec测试?_Ruby On Rails_Rspec_Controller - Fatal编程技术网

Ruby on rails 如何为仅呈现html的控制器方法编写rspec测试?

Ruby on rails 如何为仅呈现html的控制器方法编写rspec测试?,ruby-on-rails,rspec,controller,Ruby On Rails,Rspec,Controller,My routes.rb: Rails.application.routes.draw do root 'application#hello' end 我的应用程序\u controller.rb: class ApplicationController < ActionController::Base def hello render html: "Hello, world!" end end 我得到这个错误: Failures: 1) Applicatio

My routes.rb:

Rails.application.routes.draw do
  root 'application#hello'
end
我的应用程序\u controller.rb:

class ApplicationController < ActionController::Base
  def hello
    render html: "Hello, world!"
  end
end
我得到这个错误:

Failures:

  1) ApplicationController#hello renders hello world
     Failure/Error: get :hello_world

     ActionController::UrlGenerationError:
       No route matches {:action=>"hello_world", :controller=>"application"}

如何编写Rspec测试来测试此方法是否呈现此html?

错误是无法找到路由
hello\u world
,请尝试更改

it 'renders hello world' do
  get :hello_world

  expect(response.body).to include('hello world')
end


看看它是否有助于展示你的工作,你尝试了什么,什么不起作用?你是我的英雄。谢谢你指导我如何最好地在这里发帖,也感谢你让我的测试顺利进行!很高兴能帮上忙,如果答案对你有帮助,你会接受吗?
it 'renders hello world' do
  get :hello_world

  expect(response.body).to include('hello world')
end
it 'renders hello world' do
  get :hello

  expect(response.body).to include('hello world')
end