spec/integration/params_spec.rb in wayfarer-0.4.6 vs spec/integration/params_spec.rb in wayfarer-0.4.7

- old
+ new

@@ -3,54 +3,62 @@ require "spec_helpers" describe "URL parameters" do let(:url) { test_app_path("git-scm.com/book/en/v2.html") } - describe Wayfarer::Base do + 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 - class self.class::DummyJob < Wayfarer::Base + 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 do - to :index, host: test_app_host do - path "git-scm.com/book/:lang/:file" - end + 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 - - self.class::DummyJob.crawl(url) - perform_enqueued_jobs end + + it_behaves_like "executes" end - describe Wayfarer::Handler do - specify do - class self.class::DummyJob < Wayfarer::Base + describe "path pattern matching with handler" do + before do + DummyJob.class_eval do extend SpecHelpers - route do - to DummyHandler, host: test_app_host do - path "git-scm.com/book/:lang/:file" - end + route.to DummyHandler, host: test_app_host do + path "git-scm.com/book/:lang/:file" end + end - class DummyHandler < Wayfarer::Handler - include RSpec::Matchers + DummyHandler.class_eval do + include RSpec::Matchers - route { to :index } + route.to :index - def index - expect(params).to eq("lang" => "en", "file" => "v2.html") - end + def index + expect(params).to eq("lang" => "en", "file" => "v2.html") end end - - self.class::DummyJob.crawl(url) - perform_enqueued_jobs end end + + it_behaves_like "executes" end