Sha256: 0205084bd07bbee7c14db067d17f003b9a27c89a76bca0825396a74ce785b152

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe 'PGit::Project::Add' do
  describe 'user is on a project path that already exists' do
    it 'raises an error' do
      app = instance_double('PGit::Project::Application',
                            exists?: true)
      expect{PGit::Project::Add.new(app)}.to raise_error(PGit::Error::User, 'Project path already exists. See `pgit proj update --help.`')
    end
  end

  describe '#execute!' do
    it 'instantiates a project and saves it' do
      class SomeProject
        include ActiveModel::Validations
        validates_with PGit::Validators::ProjectValidator
        def get!
        end

        def kind
          'project'
        end
      end

      project = SomeProject.new
      config_project = instance_double('PGit::Project')
      projects = [config_project]
      app = instance_double('PGit::Project::Application',
                            exists?: false,
                            project: project,
                            projects: projects)
      adder = instance_double('PGit::Project::InteractiveAdder',
                              execute!: nil,
                              project: project,
                              save!: nil)
      reuse_adder = instance_double('PGit::Project::ReuseApiTokenAdder',
                                    execute!: nil,
                                    project: project)
      allow(PGit::Project::InteractiveAdder).to receive(:new).with(project).and_return(adder)
      allow(PGit::Project::ReuseApiTokenAdder).to receive(:new).with(project, projects).and_return(reuse_adder)
      add = PGit::Project::Add.new(app)
      allow(add).to receive(:puts).with("Successfully added the project!")

      add.execute!

      expect(reuse_adder).to have_received(:execute!)
      expect(adder).to have_received(:execute!)
      expect(adder).to have_received(:save!)
      expect(add).to have_received(:puts).with("Successfully added the project!")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgit-1.0.0 spec/pgit/project/add_spec.rb