【发布时间】:2016-10-21 08:47:16
【问题描述】:
我的问题
它工作的场景但是在我运行测试时在控制台中 (bin/rspec) 我收到了这个警告:
弃用警告:
不推荐使用来自 rspec-mocks 的旧
:should语法的any_instance而不显式启用该语法。改用新的:expect语法或显式启用:should。 从 /home/wakematta/github/example/spec/features/aspec/features/premium_spec.rb:3:in `block (2 levels) in '调用。如果您需要更多回溯来处理这些弃用中的任何一个 确定在哪里进行必要的更改,您可以配置
config.raise_errors_for_deprecations!,它会打开 将弃用警告转化为错误,为您提供完整的回溯。总共 1 个弃用警告
我的场景
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include ExtraContent
end
app/controllers/concerns/extra_content.rb
module ExtraContent
extend ActiveSupport::Concern
included do
helper_method :extra_content?
end
def extra_content?
current_user.premium?
end
end
app/views/users/show.html.haml
%h1= @user.name
- if extra_content?
%span.premium PREMIUM
spec/features/premium_spec.rb
feature 'Premium features' do
scenario 'premium user can view extra content' do
ApplicationController.any_instance.stub(:extra_content?).and_return(true)
visit '/users/1'
expect(page).to have_content 'PREMIUM'
end
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rspec mocking warnings