# encoding: utf-8 require 'spec_helper' describe RemoteRepository do context '#source' do it 'builds fqu for rugged' do path = '/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq('file://' + path) end it 'builds fqu for rugged from relative path' do path = 'path/to/source_repo.git' remote_repo = in_working_directory do RemoteRepository.new(path) end expect(remote_repo.source).to eq('file://' + File.join(working_directory, path)) end it 'builds fqu for rugged from relative path with dot' do path = 'source_repo.git' remote_repo = in_working_directory do RemoteRepository.new(path) end expect(remote_repo.source).to eq('file://' + File.join(working_directory, path)) end it 'handles http as well' do path = 'http://host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq(path) end it 'handles git as well' do path = 'git://host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq(path) end it 'handles git with useras well' do path = 'git://user@host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq(path) end it 'handles ssh git as well' do path = 'ssh://user@host:/opt/nwm-sec/www/repos-git/applications/test_server.git/' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq(path) end it 'handles ssh git as well without prefix' do path = 'user@host:/opt/nwm-sec/www/repos-git/applications/test_server.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.source).to eq(path) end end context '#base' do it 'handles http as well' do path = 'http://host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.base).to eq('source_repo') end it 'handles git as well' do path = 'git://host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.base).to eq('source_repo') end it 'handles git with useras well' do path = 'git://user@host/path/to/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.base).to eq('source_repo') end it 'handles ssh git as well' do path = 'ssh://user@host:/opt/nwm-sec/www/repos-git/applications/source_repo.git/' remote_repo = RemoteRepository.new(path) expect(remote_repo.base).to eq('source_repo') end it 'handles ssh git as well without prefix' do path = 'user@host:/opt/nwm-sec/www/repos-git/applications/source_repo.git' remote_repo = RemoteRepository.new(path) expect(remote_repo.base).to eq('source_repo') end it 'extracts basename without .git' do remote_repo = RemoteRepository.new('/path/to/source_repo.git') expect(remote_repo.base).to eq('source_repo') end it 'resolves ~' do remote_repo = RemoteRepository.new('~/source_repo.git') expect(remote_repo.base).to eq('source_repo') end end end