Sha256: f61634a7ea5f326f626b56d529c77718048f0975e799fc4277205d047f91797f

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe Raktr::Tasks::Delayed do
    it_should_behave_like 'Raktr::Tasks::Base'

    let(:list) { Raktr::Tasks.new }
    let(:interval) { 0.25 }
    subject { described_class.new( interval ){} }

    describe '#initialize' do
        context 'when the interval is <= 0' do
            it "raises #{ArgumentError}" do
                expect { described_class.new( 0 ){} }.to raise_error ArgumentError
                expect { described_class.new( -1 ){} }.to raise_error ArgumentError
            end
        end
    end

    describe '#interval' do
        it 'returns the configured interval' do
            subject.interval.should == interval
        end
    end

    describe '#call' do
        context 'at the next interval' do
            it 'calls the task' do
                called = 0
                task = described_class.new( interval ) do
                    called += 1
                end

                list << task

                time = Time.now
                task.call while called < 1

                elapsed = (Time.now - time).round(2)
                elapsed.should >= 0.25
                elapsed.should < 0.30
            end

            it 'calls #done' do
                called = 0
                task = described_class.new( interval ) do
                    called += 1
                end

                list << task

                task.should receive(:done)
                task.call while called < 1
            end

            context 'when arguments have been provided' do
                it 'passes them to the task' do
                    called = nil
                    task = described_class.new( interval ) do |_, s1, s2|
                        called = [s1, s2]
                    end

                    list << task

                    task.call( :stuff1, :stuff2 ) while !called

                    called.should == [:stuff1, :stuff2]
                end
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
raktr-0.0.3 spec/raktr/tasks/delayed_spec.rb
raktr-0.0.2 spec/raktr/tasks/delayed_spec.rb
raktr-0.0.1 spec/raktr/tasks/delayed_spec.rb