Skip to content

Instantly share code, notes, and snippets.

@devton
Created February 10, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devton/61665256894985a2be20 to your computer and use it in GitHub Desktop.
Save devton/61665256894985a2be20 to your computer and use it in GitHub Desktop.
Crawler::UrlParser spec
require "rails_helper"
RSpec.describe Crawler::UrlParser, :type => :service do
describe ".parse" do
subject { Crawler::UrlParser.parse url }
context "normal url" do
let(:url) { 'www.my-example.url.com' }
let(:url_attributes) {
{
url_scheme: 'http',
host: 'www.my-example.url.com',
path: '/',
fragment: nil,
query_strings: nil
}
}
it { is_expected.to eq(url_attributes) }
end
context "with fragments" do
let(:url) { 'www.my-example.url.com/#!/foo/bar' }
let(:url_attributes) {
{
url_scheme: 'http',
host: 'www.my-example.url.com',
path: '/',
fragment: '#!/foo/bar',
query_strings: nil
}
}
it { is_expected.to eq(url_attributes) }
end
context "with query strings" do
let(:url) { 'www.my-example.url.com/?foo=bar&bar=foo' }
let(:url_attributes) {
{
url_scheme: 'http',
host: 'www.my-example.url.com',
path: '/',
fragment: nil,
query_strings: 'foo=bar&bar=foo'
}
}
it { is_expected.to eq(url_attributes) }
end
context "complex with query and fragments" do
let(:url) { 'www.my-example.url.com/#!/foo/bar?foo=bar&bar=foo' }
let(:url_attributes) {
{
url_scheme: 'http',
host: 'www.my-example.url.com',
path: '/',
fragment: '#!/foo/bar',
query_strings: 'foo=bar&bar=foo'
}
}
it { is_expected.to eq(url_attributes) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment