File: clean_spec.rb

package info (click to toggle)
ruby-librarian 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 624 kB
  • sloc: ruby: 6,109; makefile: 11
file content (102 lines) | stat: -rw-r--r-- 2,919 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require "librarian/action/clean"

module Librarian
  describe Action::Clean do

    let(:env) { double }
    let(:action) { described_class.new(env) }

    before do
      allow(action).to receive(:debug)
    end

    describe "#run" do

      describe "behavior" do

        after do
          action.run
        end

        describe "clearing the cache path" do

          before do
            allow(action).to receive(:clean_install_path)
          end

          context "when the cache path is missing" do
            before do
              allow(env).to receive_message_chain(:cache_path, :exist?).and_return(false)
            end

            it "should not try to clear the cache path" do
              expect(env.cache_path).to receive(:rmtree).never
            end
          end

          context "when the cache path is present" do
            before do
              allow(env).to receive_message_chain(:cache_path, :exist?).and_return(true)
            end

            it "should try to clear the cache path" do
              expect(env.cache_path).to receive(:rmtree).exactly(:once)
            end
          end

        end

        describe "clearing the install path" do

          before do
            allow(action).to receive(:clean_cache_path)
          end

          context "when the install path is missing" do
            before do
              allow(env).to receive_message_chain(:install_path, :exist?).and_return(false)
            end

            it "should not try to clear the install path" do
              expect(env.install_path).to receive(:children).never
            end
          end

          context "when the install path is present" do
            before do
              allow(env).to receive_message_chain(:install_path, :exist?).and_return(true)
            end

            it "should try to clear the install path" do
              children = [double, double, double]
              children.each do |child|
                allow(child).to receive(:file?).and_return(false)
              end
              allow(env).to receive_message_chain(:install_path, :children).and_return(children)

              children.each do |child|
                expect(child).to receive(:rmtree).exactly(:once)
              end
            end

            it "should only try to clear out directories from the install path, not files" do
              children = [double(:file? => false), double(:file? => true), double(:file? => true)]
              allow(env).to receive_message_chain(:install_path, :children).and_return(children)

              children.select(&:file?).each do |child|
                expect(child).to receive(:rmtree).never
              end
              children.reject(&:file?).each do |child|
                expect(child).to receive(:rmtree).exactly(:once)
              end
            end
          end

        end

      end

    end

  end
end