jeudi 19 mai 2016

Rspec when retrying Begin - Rescue does not work properly

I need to test the asyncious story, so the maximum time that I need to wait for 5 mins but using retrying I would like to check the results in every 30 seconds and as soon as the test is passed, I would like to end the test. But the code that I wrote;

it "whatever" do
    @sysadmin.update!('Account', Id: @account_id_d, Status: "xyz")
    puts"For the case 2:"
    sleep 30
    begin
        puts"Checking case 2.."
        @account_a[:Status].should eq "xyz" 
        @account_b[:Status].should eq "xyz" 
        @account_c[:Status].should eq "xyz" 
        @account_e[:Status].should eq "xyz" 
        @account_f[:Status].should eq "xyz"
        @account_g[:Status].should eq "xyz"
    rescue Exception => e
        $attempts += 1
        sleep 30
        puts"Sleep Time:#{$attempts}"
        retry if $attempts < 11
        raise Exception if $attempts == 11

    end
end

It does not end the test even if the test is passed and I am getting the terminal output like this;

For the case 2:
Checking case 2..
Sleep Time:1
Checking case 2..
Sleep Time:2
Checking case 2..
Sleep Time:3
Checking case 2..
Sleep Time:4
Checking case 2..
Sleep Time:5
Checking case 2..
Sleep Time:6
Checking case 2..
Sleep Time:7
Checking case 2..
Sleep Time:8
Checking case 2..
Sleep Time:9
Checking case 2..
Sleep Time:10
Checking case 2..
Sleep Time:11

Do you help me to find what is wrong with my code and how can I end the test when it is passed?

Aucun commentaire:

Enregistrer un commentaire