ruby on rails 4 - RSpec: Problems converting to the new "allow" syntax for mocks/stubs -


i trying learn rspec , apply learning existing rails app.

i trying create mock of user called "current_user"

i have taken line of code

     controller.stub(:current_user).and_return(build_stubbed(:user)) 

and placed before tests (all of require current_user defined)

this works. but

  1. i know syntax deprecated , should using

      allow().to receive().and_return() 

syntax can't seem convert new syntax , work.

i tried

    user = double("user")     allow(user).to receive(:current_user).and_return(build_stubbed(:user)) 

without success. reality have no idea doing , need pointed in right direction. have looked extensively answer suspect basic.

would appreciate guidance.

currently, you're stubbing current_user method controller variable. in new syntax example, you've put stub on user double object.

without knowing more build_stubbed, expect like:

allow(controller).to receive(:current_user).and_return build_stubbed(:user) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -