Thursday 15 September 2011

ruby on rails - Stubbing an exception, but evaluating normally (RSpec) -


I try to update an instance variable @status on an object based on the display I am a block This block also calls for another class.

  def run @ entries.keep_if {| I | Legitimate_trance? (I)} .each do | E Unique_id = get_uniqueid e cdr_record = Start Cdr.find_by_uniqueid (unique_id). First recording = cdr_record.nil? ? NullAsteriskRecording.new: AsteriskRecording.new (cdr_record, e) recording.ass_edits recording. Import rescue exception = & gt; E fail_status end end end is a private method that updates the frequency variable in : failed . By breaking some other things, I verify this code works basically, but I also want an examination in place. Currently, I found the following:  
  reference "in which an exception is thrown" @recording = double ("asterisk_recording") @ recording. Do the stop (before importing). And_ridge ("error") should end "it should set #status: unsuccessful" Update # variable in # block "updates" to the # block "updates" subject.run subject.status.should eq: failed end Termination   

But test always fails Rescue block is never evaluated (I have checked with the statement puts , Which will be evaluated in a raise statement during hard work] Do I double feature? Or am I doing it myself by tampering an exception, so do Rescue blocks never run?

You set up your recording @ before the block, but the code you post for your run method will not use that example of @recording And so the call to record will not take exception exception in the run method.

In your run method, Ording either may terminate named NullAsteriskRecording or AsteriskRecording. If you know that this is going to be your exact recording as you are in your current test, then an approach will change before your block:

  Before the asteriskic recording. Any_instance.stub (.import) .and_ridge ("error") end    

No comments:

Post a Comment