Ruby on rails 如何为仅呈现html的控制器方法编写rspec测试?
My routes.rb: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
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