RSPEC测试请求不执行控制器/操作
我有此RSPEC测试:
RSpec.describe 'Navbar', type: :request do
describe 'GET /close_navbar' do
it 'returns http success' do
get '/close_navbar'
expect(response).to have_http_status(:ok)
end
end
end
测试控制器/操作:
class Navbar < ApplicationController
def close_navbar
raise 'closing'
session[:navbar] = :closed
head :ok
end
end
我需要它来测试会话是否具有适当的值进行更新。
但是我不认为该操作正在执行,特别是我添加了rise
行以查看,并且没有例外。
此外,测试失败了,因为返回的HTTP状态为:找到
,而不是:ok
I have this rspec test:
RSpec.describe 'Navbar', type: :request do
describe 'GET /close_navbar' do
it 'returns http success' do
get '/close_navbar'
expect(response).to have_http_status(:ok)
end
end
end
testing a controller/action:
class Navbar < ApplicationController
def close_navbar
raise 'closing'
session[:navbar] = :closed
head :ok
end
end
I need this to test that the session is updated with the proper value.
but I don't think the action is being executed, in particular I added the raise
line to see, and no exception is raised.
also the test fails because the returned http status is :found
, not :ok
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在检查响应主体时,我认为该应用程序正在将我重定向到Sign_in Action,因此这就是为什么我的动作未执行的原因。
那是正确的行为,我有测试帮助者可以在测试中登录用户。所以我使用了这些,它起作用了。
checking the response body, I figured that the app was redirecting me to sign_in action, so that's why my action wasn't executed.
that is the correct behaviour, and I have test helpers to sign in a user in the tests. so I used these and it worked.