Sha256: b53094ad1e7fc92a498a2e935b7be8b425dc68284341ae05cc855e020f0ccb8a

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

describe WorkerRoulette::Preprocessor do
  before { allow(subject).to receive(:preprocessors).and_return(preprocessors) }

  class TestClass
    include WorkerRoulette::Preprocessor
    def preprocessors
    end
  end

  module TestPreprocessor
    class TestClass
      def process(job, channel)
      end
    end
  end

  describe "#preprocess" do
    let(:wo) { double("work_order") }
    let(:result) { double("resulting_wo") }
    let(:channel) { "aChannel" }
    subject { TestClass.new }

    context "with one preprocessor" do
      let(:preprocessors) { [TestPreprocessor] }

      it "calls the correct preprocessor with the correct args" do
        expect_any_instance_of(TestPreprocessor::TestClass).to receive(:process).with(wo, channel)
        subject.preprocess(wo, channel)
      end

      it "returns the value of the preprocessor" do
        allow_any_instance_of(TestPreprocessor::TestClass).to receive(:process).and_return(result)
        expect(subject.preprocess(wo, channel)).to eq(result)
      end
    end

    context "with two preprocessors" do
      let(:preprocessors) { [TestPreprocessor, TestPreprocessor] }
      let(:intermediate) { double("intermediate_result") }

      it "chains the preprocessors and returns the correct result" do
        allow_any_instance_of(TestPreprocessor::TestClass).to receive(:process).with(wo, channel).and_return(intermediate)
        allow_any_instance_of(TestPreprocessor::TestClass).to receive(:process).with(intermediate, channel).and_return(result)

        expect(subject.preprocess(wo, channel)).to eq(result)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nexia_worker_roulette-0.2.9 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.8 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.7 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.6 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.5 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.4 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.3 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.2 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.1 spec/unit/preprocessor_spec.rb
nexia_worker_roulette-0.2.0 spec/unit/preprocessor_spec.rb