Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialogechi1
14,455 PointsUsing `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated
Hello Folks,
I'm trying to figure out how to get rid of this deprecation warning:
Deprecation Warnings:
Using `stub` 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 /Users/*/treehouse/projects/odot/spec/controllers/user_sessions_controller_spec.rb:32:in `block (4 levels) in <top (required)>'.
here's the code from my user_sessions_controller_spec.rb:
it "authenticates the user" do
User.stub(:find_by).and_return(user)
expect(user).to receive(:authenticate)
post :create, email: "jabba@thehut.com", password: "jabba12345"
end
Thanks in advance!! Ogechi
3 Answers
ogechi1
14,455 PointsI got it to work, sans deprecation errors by using this:
allow(User).to receive(:find_by).and_return(user)
instead of this:
User.stub(:find_by).and_return(user)
based on this syntax: rspec 3 - stub a class method
jason phillips
18,131 PointsI think this is the new syntax:
allow(User).to receive_message_chain(:find_by).and_return(user)
expect(user).to receive(:authenticate)
post :create, email: 'email@email.com', password: 'P@$$WORD'
ogechi1
14,455 Pointsbasically, i don't know how to update to the new syntax as specified: http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3
# old syntax:
object.stub(:foo => 1, :bar => 2)
# new syntax:
allow(object).to receive_messages(:foo => 1, :bar => 2)
# old syntax:
object.stub_chain(:foo, :bar, :bazz).and_return(3)
# new syntax:
allow(object).to receive_message_chain(:foo, :bar, :bazz).and_return(3)
Sebastian Velandia
24,676 Pointsthis is a good start point http://www.rubydoc.info/gems/rspec-mocks/frames