Sha256: 565ff6e26a1a844ae8d4c9c088a00114ee4838a34a3e63e438601b3e689d0d67

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

module BerkeleyLibrary
  module Util
    module URIs
      describe Validator do
        describe :uri_or_nil do
          it 'returns a URI unchanged' do
            uri = URI.parse('http://example.org/')
            expect(Validator.uri_or_nil(uri)).to be(uri)
          end

          it 'converts a string to a URI' do
            url = 'http://example.org/'
            expect(Validator.uri_or_nil(url)).to eq(URI.parse(url))
          end

          it 'returns nil for nil' do
            expect(Validator.uri_or_nil(nil)).to be_nil
          end

          it 'raises an error for invalid URL strings' do
            bad_url = 'not a uri'
            expect { Validator.uri_or_nil(bad_url) }.to raise_error(URI::InvalidURIError)
          end
        end

        describe :url_str_or_nil do
          it 'returns a URL string for a URI' do
            uri = URI.parse('http://example.org/')
            expect(Validator.url_str_or_nil(uri)).to eq(uri.to_s)
          end

          it 'returns a URL string' do
            url = 'http://example.org/'
            expect(Validator.url_str_or_nil(url)).to eq(url)
          end

          it 'returns nil for nil' do
            expect(Validator.url_str_or_nil(nil)).to be_nil
          end

          it 'raises an error for invalid URL strings' do
            bad_url = 'not a uri'
            expect { Validator.url_str_or_nil(bad_url) }.to raise_error(URI::InvalidURIError)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
berkeley_library-util-0.1.9 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.8 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.7 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.6 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.5 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.4 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.3 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.2 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.1 spec/berkeley_library/util/uris/validator_spec.rb
berkeley_library-util-0.1.0 spec/berkeley_library/util/uris/validator_spec.rb