Skip to content

Commit 7985c3f

Browse files
committed
Add format matchers spec
There are already format for email, url, and link_url, but the spec was missing.
1 parent a994f7c commit 7985c3f

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe Alchemy::Configurations::FormatMatchers do
6+
subject(:format_matchers) { described_class.new }
7+
8+
describe "#email" do
9+
it "matches valid emails" do
10+
expect("user@example.com").to match(format_matchers.email)
11+
end
12+
13+
it "does not match invalid emails" do
14+
expect("not-an-email").not_to match(format_matchers.email)
15+
expect("user@").not_to match(format_matchers.email)
16+
expect("@example.com").not_to match(format_matchers.email)
17+
end
18+
end
19+
20+
describe "#url" do
21+
it "matches valid URLs" do
22+
expect("example.com").to match(format_matchers.url)
23+
expect("sub.example.com").to match(format_matchers.url)
24+
expect("example.com:8080").to match(format_matchers.url)
25+
expect("example.com/path").to match(format_matchers.url)
26+
end
27+
28+
it "does not match invalid URLs" do
29+
expect("not a url").not_to match(format_matchers.url)
30+
end
31+
end
32+
33+
describe "#link_url" do
34+
it "matches tel: links" do
35+
expect("tel:+1234567890").to match(format_matchers.link_url)
36+
end
37+
38+
it "matches mailto: links" do
39+
expect("mailto:user@example.com").to match(format_matchers.link_url)
40+
end
41+
42+
it "matches absolute paths" do
43+
expect("/some/path").to match(format_matchers.link_url)
44+
end
45+
46+
it "matches protocol URLs" do
47+
expect("https://example.com").to match(format_matchers.link_url)
48+
expect("http://example.com").to match(format_matchers.link_url)
49+
end
50+
51+
it "does not match relative paths" do
52+
expect("relative/path").not_to match(format_matchers.link_url)
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)