当我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)
这是我的控制器规格: -
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.
我不知道如何更改我有的代码,以便警告不再出现。
弃用信息非常明确,您究竟不知道什么?你有没有试图用新风格重写代码? –
@Зелёный如果你看看他们的代码示例,你会发现他们已经在使用关键字参数,所以似乎没有任何理由反对弃用消息。 – janfoeh
@janfoeh没有像'message'这样的东西,只有'params,headers,env,xhr',所以我假设他没有尝试。 –