如何解决如何在 rspec rails6 中获取/发布方法
刚接触 Rails
我正在使用 RSpec gem 进行测试
这是我的控制器
class QuestionsController < ApplicationController
before_action :require_user,except: %i[show index]
before_action :authorize_user,only: %i[edit update destroy]
def index
@questions = Question.all
end
def show
@answers = Answer.where('question_id = :question_id ',{ question_id: params[:id] })
@count = Answer.where('question_id = :question_id ',{ question_id: params[:id] }).count
$count_global = @count
session[:question_id] = params[:id]
@questions = Question.all
end
def new
@question = Question.new
end
def edit; end
def create
@question = Question.new(question_params)
@question.user_id *strong text*= current_user.id
@question.save
redirect_to root_path
end
end
这是spec/requests/question_spec.rb
describe "GET /new" do
it "renders a successful response" do
get new_question_url
expect(response).to be_successful
end
end
测试未通过 错误是
Failure/Error: expect(response).to be_successful
expected `#<ActionDispatch::TestResponse:0x0000558594f082e0 @mon_data=#<Monitor:0x0000558594f08290>,@mon_data_...,@method=nil,@request_method=nil,@remote_ip=nil,@original_fullpath=nil,@fullpath=nil,@ip=nil>>.successful?` to be truthy,got false
有人可以帮忙解决这个问题吗
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。