Ruby on Rails Method Mocks in the Controller -


i'm trying mock method call outside api inside 1 of rails controllers (in case, instagram.get_access_token) , i'm having trouble. written, code still calling real instagram.get_access_token method. how have controller use simple mock instead?

sessions_controller.rb:

class sessionscontroller < applicationcontroller    require 'instagram'   include applicationhelper    def auth_callback     response = instagram.get_access_token(params[:code],                                           redirect_uri: auth_callback_url)     #<snipped code>   end end 

sessions_controller_spec.rb:

require 'spec_helper' require 'ostruct'  describe sessionscontroller   describe "get #auth_callback"     context "when there existing user"       let(:response) { openstruct.new(access_token: "good_access_token") }        "parses access_token response"         instagram.should_receive(:get_access_token).and_return(response)          #<snipped code>       end     end   end end 

try:

instagram.stub(:get_access_token) { response } 

do have same result?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -