Thanks Jon, sorry my bad English. The `allow(controller).to 
receive(:verify_sms_code) { { ‘code’ => 200 } }` only sets the create 
action returns {'code':200} ,but I want to let `verify_sms_code` method 
returns {'code':200} or {'code': 404} ,so that I can test create action 
with `verify_sms_code` method different returns 

在 2016年3月3日星期四 UTC+8上午8:17:55,Jon Rowe写道:
>
> Assuming you’re doing a controller spec you could do something like 
> `allow(controller).to receive(:verify_sms_code) { { ‘code’ => 200 } }`
>
> Jon Rowe
> ---------------------------
> [email protected] <javascript:>
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>.
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/8410970d-fd70-48e4-9c93-87ef958c8496%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to