【发布时间】:2018-06-08 01:14:39
【问题描述】:
我的路线.rb:
Rails.application.routes.draw do
root 'application#hello'
end
我的 application_controller.rb:
class ApplicationController < ActionController::Base
def hello
render html: "Hello, world!"
end
end
我已经尝试过这个规范,但它不起作用:
RSpec.describe ApplicationController do
render_views
describe '#hello' do
it 'renders hello world' do
get :hello_world
expect(response.body).to include("Hello, world!")
end
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?
【问题讨论】:
-
展示你的工作,你尝试了什么,什么没用?
标签: ruby-on-rails rspec controller