require 'spec_helper' describe RightPublish::GemRepo do before(:each) do @install_expectations = [] @repo_subdir = 'fake/' @repo = flexmock(RightPublish::RepoManager.get_repository(:gem_repo)) do |obj| obj.should_receive(:pull) obj.should_receive(:annotate) obj.should_receive(:push) obj.should_receive(:do_in_subdir).and_return {|dir,block| block.call} obj.should_receive(:lock).and_yield end flexmock(File) { |obj| obj.should_receive(:file?).and_return(true) } flexmock(RightPublish::Profile) do |obj| obj.should_receive(:log).and_return { |str,dbg| } obj.should_receive(:config).and_return { { :verbose=>false, :remote_storage=>{:provider=>'mockremote'}, :local_storage=>{:provider=>'mocklocal'}, :gem_repo=>{:subdir=>@repo_subdir} } } end end after(:each) do @install_expectations.should be_empty end context "#publish" do def build_expectations(pkgs) @install_expectations = Array(pkgs) @repo.should_receive(:install_file).and_return do |pkg,dir| @install_expectations.delete(pkg) dir.should be_eql(File.join(@repo_subdir, RightPublish::GemRepo::GEMS_SUBDIRECTORY )) end @repo.should_receive(:system).once.and_return(0) end it "should install a single gem file" do gem_file = 'foo-1.gem' build_expectations(gem_file) @repo.publish(gem_file, nil) end it "should install a list of gem files" do gem_files = ['foo-1.gem', 'bar-2.0.0.gem'] build_expectations(gem_files) @repo.publish(gem_files, nil) end it "should glob a directory of gem files and install them" do gem_files = ['foo-1.gem', 'bar_game-2.0.gem'] build_expectations(gem_files) flexmock(File) { |obj| obj.should_receive(:directory?).and_return(true) } flexmock(Dir) { |obj| obj.should_receive(:glob).and_return(gem_files) } @repo.publish('some_dir/', nil) end it "should fail with no files in a dir" do flexmock(File) { |obj| obj.should_receive(:directory?).and_return(true) } flexmock(Dir) { |obj| obj.should_receive(:glob).and_return([]) } @repo.should_receive(:system).never expect { @repo.publish('some_dir/', nil) }.to raise_error(RuntimeError) end it "should fail with files without a gem extenstion" do gem_files = ['foo-1.gem', 'bar-2.rpm'] @repo.should_receive(:system).never expect { @repo.publish(gem_files, nil) }.to raise_error(RuntimeError) end end end