gpt4 book ai didi

ruby-on-rails - 在功能测试中使用位置参数已被弃用

转载 作者:行者123 更新时间:2023-12-03 18:08:09 27 4
gpt4 key购买 nike

我在运行 rspec 时收到此警告:-

DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.

Deprecated style:
get :show, { id: 1 }, nil, { notice: "This is a flash message" }

New keyword style:
get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
session: nil # Can safely be omitted.
(called from block (4 levels) in <top (required)> at /home/user/organization/fooobarr/spec/controllers/contacts_controller_spec.rb:13)

这是我的 Controller 规范:-
require 'rails_helper'

RSpec.describe ContactsController, :type => :controller do

describe "#create" do
it "sends an email when message is valid" do
expect{
post :create, message: attributes_for(:message)
}.to change{ ActionMailer::Base.deliveries.count }.by(1)
end

it "does not send email when message is invalid" do
expect{
post :create, message: {subject: "", name: "",
email:"", content: ""}
}.to change{ ActionMailer::Base.deliveries.count }.by(0)
end
end
end

在第 13 和 19 行抛出错误。

我不确定如何更改我拥有的代码,以便不再出现警告。

最佳答案

为了将来引用,您还可以使用 Rubocop 的自动修复功能修复这些(批量!):

http://rubocop.readthedocs.io/en/latest/cops_rails/#railshttppositionalarguments

bundle exec rubocop --rails --only HttpPositionalArguments --auto-correct

记得设置 TargetRailsVersion: 5.0 Rubocop 配置中的或更高版本,以启用该警察。

关于ruby-on-rails - 在功能测试中使用位置参数已被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44567034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com