Issue
My question
The scenario it works but in the console when I run the tests (bin/rspec
) I get this warning:
Deprecation Warnings:
Using
any_instance
from rspec-mocks' old:should
syntax without explicitly enabling the syntax is deprecated. Use the new:expect
syntax or explicitly enable:should
instead. Called from /home/wakematta/github/example/spec/features/aspec/features/premium_spec.rb:3:in `block (2 levels) in '.If you need more of the backtrace for any of these deprecations to identify where to make the necessary changes, you can configure
config.raise_errors_for_deprecations!
, and it will turn the deprecation warnings into errors, giving you the full backtrace.1 deprecation warning total
My scenario
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
Solution
Change this:
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
For this:
spec/features/premium_spec.rb
feature 'Premium features' do
scenario 'premium user can view extra content' do
allow_any_instance_of(ApplicationController).to receive(:extra_content?).and_return(true)
visit '/users/1'
expect(page).to have_content 'PREMIUM'
end
end
Answered By - Mohamed Ziata Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.