# frozen_string_literal: true

require 'spec_helper'
require 'git/commands/stash/clear'

RSpec.describe Git::Commands::Stash::Clear, :integration do
  include_context 'in an empty repository'

  subject(:command) { described_class.new(execution_context) }

  before do
    # Create initial commit
    write_file('file.txt', "initial content\n")
    repo.add('file.txt')
    repo.commit('Initial commit')
  end

  describe '#call' do
    describe 'when the command succeeds' do
      it 'returns CommandLineResult' do
        result = command.call

        expect(result).to be_a(Git::CommandLine::Result)
        expect(result.status.exitstatus).to eq(0)
      end
    end

    describe 'when the command fails' do
      before { FileUtils.rm_rf(File.join(repo_dir, '.git')) }

      it 'raises FailedError when the repository is missing' do
        expect { command.call }.to raise_error(Git::FailedError)
      end
    end
  end
end
