Sha256: 572c6abac3dd7f0e30959b6a1392b857acacf5c52bfac3695ffa3795ce8e3643

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Arachni::Reactor::Tasks::Periodic do
    it_should_behave_like 'Arachni::Reactor::Tasks::Base'

    let(:list) { Arachni::Reactor::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 each interval' do
            it 'calls the task' do
                called = 0
                task = described_class.new( interval ) do
                    called += 1
                end

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

                elapsed = (Time.now - time).round(2)
                elapsed.should >= 1.25
                elapsed.should < 1.35
            end
        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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arachni-reactor-0.1.3.2 spec/arachni/reactor/tasks/periodic_spec.rb
arachni-reactor-0.1.3.1 spec/arachni/reactor/tasks/periodic_spec.rb
arachni-reactor-0.1.3 spec/arachni/reactor/tasks/periodic_spec.rb
arachni-reactor-0.1.2 spec/arachni/reactor/tasks/periodic_spec.rb
arachni-reactor-0.1.1 spec/arachni/reactor/tasks/periodic_spec.rb