Assuming you’re doing a controller spec you could do something like 
`allow(controller).to receive(:verify_sms_code) { { ‘code’ => 200 } }`

Jon Rowe
---------------------------
m...@jonrowe.co.uk
jonrowe.co.uk


On Wednesday, 2 March 2016 at 18:43, Ryman wrote:

> class SessionsController < ApplicationController::Base   
>   def create
>       result = verify_sms_code(params[:session][:phone], 
> params[:session][:code]
>        if result['code'] == 200
>          render json: {code: 200, msg: 'success'}
>        else
>          render json: {code: 404, msg: 'failed'}
>        end
>     end
> end
>  
> I want to mock verify_sms_code method returns JSON result,e.g {'code':200, 
> data:'correct'} or {'code':404, data:'incorrect'} ,how can I test this action 
> with verify_sms_code method different return values?  Thanks!
>  
> --  
> You received this message because you are subscribed to the Google Groups 
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rspec+unsubscr...@googlegroups.com 
> (mailto:rspec+unsubscr...@googlegroups.com).
> To post to this group, send email to rspec@googlegroups.com 
> (mailto:rspec@googlegroups.com).
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/848b2139-5848-4b41-a471-6c42085fe5df%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/rspec/848b2139-5848-4b41-a471-6c42085fe5df%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To post to this group, send email to rspec@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/019915ADF12042178C68E7A794FF6420%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to