# frozen_string_literal: true require "spec_helpers" describe Wayfarer::Middleware::Stage do include ActiveJob::TestHelper let(:task) { build(:task) } subject(:stage) { Wayfarer::Middleware::Stage.new } describe "#call" do it "assigns staged URLs" do stage.call(task) do expect(task.metadata.staged_urls).to eq(SortedSet.new) end end it "yields" do expect { |spy| stage.call(task, &spy) }.to yield_control end describe "Task queuing" do let(:klass) { Class.new(Wayfarer::Base) } let(:urls) { %w[https://example.com https://w3c.org] } before { task.job = klass.new } it "enqueues tasks" do expect(klass).to receive(:crawl_later).with(urls.first, batch: task.batch) expect(klass).to receive(:crawl_later).with(urls.second, batch: task.batch) stage.call(task) do extend Wayfarer::Middleware::Stage::API stage(urls) end end end end end