预期响应的状态代码为200,但RSpec中的请求测试中的状态代码为302 [英] Expected the response to have status code 200 but it was 302 in requests test in rspec

查看:0
本文介绍了预期响应的状态代码为200,但RSpec中的请求测试中的状态代码为302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现其他人发布了很多类似的问题,但没有一个解决方案起作用。

我的/SPEC/REQUESTS/QUIES_SPEC.rb是

require 'rails_helper'
RSpec.describe "Questions", type: :request do
  describe "GET /questions" do
    it "works! (now write some real specs)" do
      get questions_path
      expect(response).to have_http_status(200)
    end
  end
end

现在我的RSpec错误

Questions GET /questions works! (now write some real specs)
 Failure/Error: expect(response).to have_http_status(200)
   expected the response to have status code 200 but it was 302
 # ./spec/requests/questions_spec.rb:7:in `block (3 levels) in <top (required)>'

有人能帮我吗?如何自定义代码以获取状态代码200?

推荐答案

302 - Found。我认为您使用的是Rails脚手架。GET方法上的scaffold语法返回302状态。如果你需要200的话。您可以自定义代码。

这篇关于预期响应的状态代码为200,但RSpec中的请求测试中的状态代码为302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆