Sha256: 7f59b56a556423a0706f9bedec15c012dbf76dd610c76358a1c6ae72f282d2af

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe Alephant::Scout::Url do
  describe ".valid?(url)" do
    let(:response) { double('HTTParty::Response') }
    it "is a valid url" do
      allow(response).to receive(:code).and_return(200)
      allow(HTTParty).to receive(:head).and_return(response)
      expect(subject.valid?('http://www.avalidurl.com')).to be true
    end

    it "is a valid url with an issue" do
      allow(response).to receive(:code).and_return(500)
      allow(HTTParty).to receive(:head).and_return(response)
      expect(subject.valid?('http://www.notavalidurl.com')).to be false
    end

    it "is an invalid URL - i.e. host is resolved but resource does not exist" do
      allow(response).to receive(:code).and_return(404)
      allow(HTTParty).to receive(:head).and_return(response)
      expect(subject.valid?('http://www.avalidurl.com/but/a/nonexistent/resource')).to be false
    end

    it "is an invalid host - i.e. no DNS resolution" do
      allow(response).to receive(:code).and_return(500)
      allow(HTTParty).to receive(:head).and_raise("Hostname not found")
      expect(subject.valid?('test://www.notavalidurl.test')).to be false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-scout-0.0.1 spec/url_spec.rb