【发布时间】:2017-05-04 06:17:29
【问题描述】:
我刚刚将我的 5.0.1 应用升级到 5.1,每当我运行我的 rspec 测试时,我都会收到大量的警告。
DEPRECATION WARNING: ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2. (called from <top (required)> at /home/doomy/Documents/rsm/config/initializers/new_framework_defaults.rb:23)
...DEPRECATION WARNING: The behavior of `changed_attributes` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes.transform_values(&:first)` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `changes` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `changed` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes.keys` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
DEPRECATION WARNING: The behavior of `attribute_change` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute` instead. (called from block (3 levels) in <top (required)> at /home/doomy/Documents/rsm/spec/controllers/products_spec.rb:48)
这对于我进行的每一项测试都会进行,并且最终花费了相当长的时间,因为它要编写很多东西来控制台。
我对我应该改变什么感到很困惑,因为有问题的代码看起来并没有什么不寻常的地方。
这是第 48 行附近的 products_spec.rb
describe "GET show" do
before(:each) do
@product = create(:product, user: create(:product_admin))
end
context "anonymously" do
it "renders" do
get :show, params: { id: @product.id }
expect(response).to render_template("show")
end
end
context "as regular user" do
it "renders" do
get :show, params: { id: @product.id }
login(create(:user))
expect(response).to render_template("show")
end
end
...
我认为它必须与 before 过滤器有关,但我不太清楚是什么。搜索警告不会返回任何有用的信息。
谢谢。
【问题讨论】:
-
@Зелёный 是的 - 所有的消息都说了类似的话。我的问题是我做错了什么,因为我在它引用的行中没有消息中提到的任何代码,我不确定如何解决这个问题。也许这对你来说很明显,但我完全迷路了。
标签: ruby-on-rails unit-testing rspec ruby-on-rails-5