Sha256: 144ce44aeb2e516d8e9232ba419e9a54bd2faf3146da7c933d46076e6d946f2d
Contents?: true
Size: 1.53 KB
Versions: 4
Compression:
Stored size: 1.53 KB
Contents
# encoding: utf-8 require 'spec_helper' describe FormatUrl do describe ".format_url" do it "adds http:// to a URL if not provided" do FormatUrl.format_url("example.com").should eq("http://example.com") end it "does not add http:// to a URL if already provided" do FormatUrl.format_url("http://example.com").should eq("http://example.com") end it "returns an invalid URL unchanged" do FormatUrl.format_url("foo bar").should eq("foo bar") FormatUrl.format_url(nil).should eq(nil) end end describe ".url_regexp" do it "matches valid URLs" do [ 'http://example.com/', 'HTTP://E-XAMLE.COM', 'https://example.co.uk./foo', 'http://example.com:8080', 'http://www.example.com/anything/after?slash', 'http://www.example.com?anything_after=question', 'http://user123:sEcr3t@example.com', 'http://user123:@example.com', 'http://example.com/~user', 'http://1.2.3.4:8080', 'http://ütf8.com', ].each do |url| url.should match(FormatUrl.url_regexp) end end it "does not match invalid URLs" do [ "www.example.com", "http://", "http://example..com", "http://e xample.com", "http://example.com/foo bar", "http://example", # technically valid but not what we want from user "other://example.com", # we also don't want other protocols ].each do |url| url.should_not match(FormatUrl.url_regexp) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
format_url-0.0.4 | spec/format_url_spec.rb |
format_url-0.0.3 | spec/format_url_spec.rb |
format_url-0.0.2 | spec/format_url_spec.rb |
format_url-0.0.1 | spec/format_url_spec.rb |