drapergem / draper

Decorators/View-Models for Rails Applications
MIT License
5.22k stars 527 forks source link

Use current rspec API for rspec stub example in README #855

Closed jrochkind closed 5 years ago

jrochkind commented 5 years ago

Current README example for stubbing in Rspec is both deprecated and does not work in a default Rspec install.

In rspec 3, if you try:

helpers.stub(users_path: '/users')

You get a deprecation warning:

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.

And in addition to the deprecation warning, it actually fails with a message:

#<Draper::HelperProxy: ...  [lots of text] ... does not implement: users_path

If we switch to 'new' rspec API allow(:helpers).to receive(:users_path).and_return("/users"), we don't get the deprecation method, but still get the failure with same error message.

If we additionally wrap in without_partial_double_verification introduced in RSpec 3.6 in May 2017, all is well.

It would save the user a lot of time to provide a nice non-deprecated working-under-default-Rspec example for RSpec stubbing, instead of giving them deprecated/non-working example and making them figure it out.

jrochkind commented 5 years ago

thank you!