【发布时间】:2018-06-26 07:09:40
【问题描述】:
我发现其他人发布了很多类似的问题,但没有一个解决方案有效。
我的 /spec/requests/questions_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?
【问题讨论】:
-
200 成功,302 找到。 Rails 脚手架在 get 方法上返回 302。
-
你能在这里分享你的控制器代码吗?
-
也许您的应用中有身份验证,这就是请求返回 302 的原因
-
您是否为此控制器使用身份验证? @Sridhar
标签: ruby-on-rails rspec rspec-rails