Sha256: c2959a24153dcd1257aaff81a7cadf939a3228a5f283d4b7970a02fd13e6a044

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

require 'spec_helper'
require 'method_decorators/decorators/retry'

describe Retry do
  let(:method) { double(:method, :call => false) }
  subject { Retry.new(3) }

  describe "#call" do
    it "executes the method again if the first time failed " do
      method.stub(:call){ raise }

      method.should_receive(:call).exactly(3).times
      expect{ subject.call(method) }.to raise_error
    end

    it "does not retry the method if it succeeds" do
      method.should_receive(:call).once.and_return(3)
      subject.call(method).should == 3
    end
  end

  describe "acceptance" do
    let(:klass) do
      Class.new Base do
        +Retry.new(3)
        def do_it(magic_number)
          @times ||= 0
          @times += 1
          raise  if @times == magic_number
          @times
        end
      end
    end
    subject { klass.new }

    it "memoizes calls to the method" do
      subject.do_it(1).should == 2
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
method_decorators-0.9.1 spec/decorators/retry_spec.rb