當我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',所以我假設他沒有嘗試。 –