# frozen_string_literal: true require "spec_helpers" describe Wayfarer::Routing::Matchers::Host do subject(:matcher) { Wayfarer::Routing::Matchers::Host.new(str_or_regexp) } describe "#matches?" do describe "String matching" do let(:str_or_regexp) { "example.com" } context "with matching URL" do let(:url) { Addressable::URI.parse("http://example.com/foo/bar") } it "returns true" do expect(matcher).to match(url) end end context "with mismatching URL" do let(:url) { Addressable::URI.parse("http://google.com/bar/qux") } it "returns false" do expect(matcher).not_to match(url) end end end describe "RegExp matching" do let(:str_or_regexp) { /example.com/ } context "with matching URL" do let(:url) { Addressable::URI.parse("http://sub.example.com") } it "returns true" do expect(matcher).to match(url) end end context "with mismatching URL" do let(:url) { Addressable::URI.parse("http://example.sub.com") } it "returns false" do expect(matcher).not_to match(url) end end end end end