Sha256: 8e1c68acaeb2b5fb095e7d8e432804b1ce3af1e37e1f4bd1ff699314f58f0579

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe Restfulie::Client::Feature::RetryWhenUnavailable do
  
  before do
    @feature = Restfulie::Client::Feature::RetryWhenUnavailable.new
    @response = mock Net::HTTPResponse
    @request = Object.new
    @chain = mock Restfulie::Client::StackNavigator
    @chain.should_receive(:continue).and_return(@response)
  end
  
  context "when executing a request" do
    
    it "should retry execution by default if response code is 503" do
      second_response = mock Net::HTTPResponse
      @chain.should_receive(:continue).with(@request, {}).and_return(second_response)
      @response.stub(:code).and_return(503)
      @feature.execute(@chain, @request, {}).should == second_response
    end
    
    it "should not retry execution by default if response code is not 503" do
      @response.stub(:code).and_return(404)
      @feature.execute(@chain, @request, {}).should == @response
    end
    
    it "should retry execution with a custom behavior" do
      def @feature.should_retry?(response, env)
        env["force_retry"] == true
      end
      second_response = mock Net::HTTPResponse
      @chain.should_receive(:continue).and_return(second_response)
      @feature.execute(@chain, @request, {"force_retry" => true}).should == second_response
    end
    
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 spec/unit/client/feature/retry_when_unavailable_spec.rb
restfulie-1.1.1 spec/unit/client/feature/retry_when_unavailable_spec.rb
restfulie-1.1.0 spec/unit/client/feature/retry_when_unavailable_spec.rb
restfulie-nosqlite-1.0.3 spec/unit/client/feature/retry_when_unavailable_spec.rb
restfulie-1.0.3 spec/unit/client/feature/retry_when_unavailable_spec.rb