Sha256: cb1c2a72eba157e0674eb2b525100fc18943655538590e4b4ce9f92b3022583c

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe 'PGit::Command::Run' do
  describe '#run' do
    it 'raises a command not found exception if the item does not exist' do
      global_opts = {}
      opts = {}
      args = ['non_existent_command']
      project = instance_double('PGit::CurrentProject')

      app = instance_double('PGit::Command::Application',
                                 commands: [],
                                 args: args,
                                 opts: opts,
                                 global_opts: global_opts,
                                 current_project: project)

      run = PGit::Command::Run.new(app)
      error_message = "Command '#{args[0]}' does not exist. Run 'pgit cmd show' to see the available custom commands."

      expect do
        run.execute!
      end.to raise_error(PGit::Error::User, error_message)
    end

    it 'calls execute on the command if it exists' do
      existent_name = 'existent_command'
      global_opts = {}
      opts = {}
      args = [existent_name]

      fake_command = instance_double('PGit::Command', name: existent_name)
      allow(fake_command).to receive(:execute)
      project = instance_double('PGit::CurrentProject')
      app = instance_double('PGit::Command::Application',
                                 commands: [fake_command],
                                 args: args,
                                 opts: opts,
                                 global_opts: global_opts,
                                 current_project: project
                           )

      run = PGit::Command::Run.new(app)
      run.execute!

      expect(fake_command).to have_received(:execute)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgit-1.0.0 spec/pgit/command/run_spec.rb