Sha256: b2ddc5b60e9176c3279d4f495edfbccb136092508ac7a9582590b7b97a793da9

Contents?: true

Size: 1.8 KB

Versions: 9

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'
require 'timecop'

module Nestene


  describe AutonExecutionQueue do

    before do
      Timecop.freeze(Time.local(1990))
    end

    after do
      Timecop.return
    end

    describe '#remove_delayed_method' do
      context "when the delayed method has been scheduled" do
        let (:delayed_method_uuid) {subject.add_delayed_method(:some_method, ['p1','p2'], 0.3).uuid}

        it "should remove the delayed method" do
          uuid = delayed_method_uuid
          subject.remove_delayed_method(uuid)

          expect(subject.delayed).to be_empty

        end
      end
    end


    describe '#add_delayed_method' do

      let(:every) { nil }

      before {subject.add_delayed_method :some_method, ['p1','p2'], 0.3, every}

      it "should add a delayed method" do
        expect(subject.delayed).to_not be_empty
      end

      it "should assign proper execute_at to delayed method" do
        expect(subject.delayed.first.execute_at).to eq(Time.now + 0.3)
      end

      it "should assign uuid to delayed method" do
        expect(subject.delayed.first.uuid).to_not be_nil
      end

      it "should assign scheduled_at to delayed method" do
        expect(subject.delayed.first.scheduled_at).to eq(Time.now)
      end

      it "should assign parameters to delayed method" do
        expect(subject.delayed.first.parameters).to eq(["p1", "p2"])
      end


      it "should sort delayed methods by their execute_at times in ascending order" do
        subject.add_delayed_method :sooner_method, ['p1','p2'], 0.1

        expect(subject.delayed.first.name).to eq(:sooner_method)
      end

      context "when every is not nil" do

        let(:every) { 0.5 }

        it "should set every value" do
          expect(subject.delayed.first.every).to eq(every)
        end

      end


    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nestene-0.1.8 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.7 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.6 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.5 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.4 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.3 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.2 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.1 spec/nestene/auton_execution_queue_spec.rb
nestene-0.1.0 spec/nestene/auton_execution_queue_spec.rb