# frozen_string_literal: true require "spec_helpers" describe "URL parameters" do let(:url) { test_app_path("git-scm.com/book/en/v2.html") } before do stub_const("DummyJob", Class.new(ActiveJob::Base).include(Wayfarer::Base)) stub_const("DummyHandler", Class.new.include(Wayfarer::Handler)) end shared_examples "executes" do specify do DummyJob.crawl(url) perform_enqueued_jobs assert_performed_jobs 1 expect(enqueued_jobs).to be_empty end end describe "path pattern matching" do before do DummyJob.class_eval do extend SpecHelpers include RSpec::Matchers route.to :index, host: test_app_host do path "git-scm.com/book/:lang/:file" end def index expect(params).to eq("lang" => "en", "file" => "v2.html") end end end it_behaves_like "executes" end describe "path pattern matching with handler" do before do DummyJob.class_eval do extend SpecHelpers route.to DummyHandler, host: test_app_host do path "git-scm.com/book/:lang/:file" end end DummyHandler.class_eval do include RSpec::Matchers route.to :index def index expect(params).to eq("lang" => "en", "file" => "v2.html") end end end end it_behaves_like "executes" end