File: clean_machine_folder_spec.rb

package info (click to toggle)
vagrant-libvirt 0.12.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,756 kB
  • sloc: ruby: 12,865; xml: 2,465; sh: 373; javascript: 235; makefile: 13
file content (59 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require_relative '../../spec_helper'

require 'vagrant-libvirt/action/clean_machine_folder'

describe VagrantPlugins::ProviderLibvirt::Action::CleanMachineFolder do
  subject { described_class.new(app, env) }

  include_context 'unit'

  describe '#call' do
    before do
      FileUtils.touch(File.join(machine.data_dir, "box.meta"))
    end

    context 'with default options' do
      it 'should verbosely remove the folder' do
        expect(ui).to receive(:info).with('Deleting the machine folder')

        expect(subject.call(env)).to be_nil

        expect(File.exist?(machine.data_dir)).to eq(true)
        expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
      end
    end

    context 'when the data dir doesn\'t exist' do
      before do
        Dir.mktmpdir do |d|
          # returns a temporary directory that has been already deleted when running
          expect(machine).to receive(:data_dir).and_return(d.to_s).exactly(3).times
        end
      end

      it 'should remove the folder' do
        expect(ui).to receive(:info).with('Deleting the machine folder')

        expect(subject.call(env)).to be_nil

        expect(File.exist?(machine.data_dir)).to eq(true)
        expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
      end
    end

    context 'with quiet option enabled' do
      subject { described_class.new(app, env, {:quiet => true}) }

      it 'should quietly remove the folder' do
        expect(ui).to_not receive(:info).with('Deleting the machine folder')

        expect(subject.call(env)).to be_nil

        expect(File.exist?(machine.data_dir)).to eq(true)
        expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
      end
    end
  end
end