spec/agent/sanitizers_spec.rb in spidr-0.5.0 vs spec/agent/sanitizers_spec.rb in spidr-0.6.0

- old
+ new

@@ -2,61 +2,55 @@ require 'spec_helper' describe Agent do describe "sanitizers" do - describe "sanitize_url" do - let(:url) { 'http://host.com' } - before(:all) { @agent = Agent.new } + describe "#sanitize_url" do + let(:url) { 'http://example.com/page?q=1#fragment' } + let(:uri) { URI(url) } - it "should sanitize URLs" do - agent = Agent.new - clean_url = agent.sanitize_url(URI(url)) + it "should sanitize URIs" do + clean_url = subject.sanitize_url(uri) - expect(clean_url.host).to eq('host.com') + expect(clean_url.host).to eq('example.com') end it "should sanitize URLs given as Strings" do - agent = Agent.new - clean_url = agent.sanitize_url(url) + clean_url = subject.sanitize_url(url) - expect(clean_url.host).to eq('host.com') + expect(clean_url.host).to eq('example.com') end - end - describe "strip_fragments" do - let(:url) { URI("http://host.com/page#lol") } - it "should strip fragment components by default" do - agent = Agent.new - clean_url = agent.sanitize_url(url) + clean_url = subject.sanitize_url(url) expect(clean_url.fragment).to be_nil end - it "should allow perserving fragment components" do - agent = Agent.new(strip_fragments: false) - clean_url = agent.sanitize_url(url) + it "should not strip query components by default" do + clean_url = subject.sanitize_url(uri) - expect(clean_url.fragment).to eq('lol') + expect(clean_url.query).to eq('q=1') end - end - describe "strip_query" do - let(:url) { URI("http://host.com/page?x=1") } + context "when strip_fragments is disabled" do + subject { described_class.new(strip_fragments: false) } - it "should not strip query components by default" do - agent = Agent.new - clean_url = agent.sanitize_url(url) + it "should perserve the fragment components" do + clean_url = subject.sanitize_url(uri) - expect(clean_url.query).to eq('x=1') + expect(clean_url.fragment).to eq('fragment') + end end - it "should allow stripping of query components" do - agent = Agent.new(strip_query: true) - clean_url = agent.sanitize_url(url) + context "when strip_query is enabled" do + subject { described_class.new(strip_query: true) } - expect(clean_url.query).to be_nil + it "should allow stripping of query components" do + clean_url = subject.sanitize_url(uri) + + expect(clean_url.query).to be_nil + end end end end end