Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 156 lines (127 sloc) 4.192 kb
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
require 'spec_helper'
require 'fpm/cookery/path_helper'

describe "PathHelper" do
  let(:helper) do
    Class.new {
      include FPM::Cookery::PathHelper

      def destdir; FPM::Cookery::Path.new('/tmp/dest') end
    }.new
  end

  describe "path helper methods" do
    [ ['prefix', '/usr'],
      ['root_prefix', '/'],
      ['root', '/'],
      ['etc', '/etc'],
      ['opt', '/opt'],
      ['var', '/var'],
      ['bin', '/usr/bin'],
      ['doc', '/usr/share/doc'],
      ['include', '/usr/include'],
      ['info', '/usr/share/info'],
      ['lib', '/usr/lib'],
      ['libexec', '/usr/libexec'],
      ['man', '/usr/share/man'],
      ['man1', '/usr/share/man/man1'],
      ['man2', '/usr/share/man/man2'],
      ['man3', '/usr/share/man/man3'],
      ['man4', '/usr/share/man/man4'],
      ['man5', '/usr/share/man/man5'],
      ['man6', '/usr/share/man/man6'],
      ['man7', '/usr/share/man/man7'],
      ['man8', '/usr/share/man/man8'],
      ['sbin', '/usr/sbin'],
      ['share', '/usr/share'] ].each do |m|

      name, path = m

      describe "##{name}" do
        def c(path); path.gsub(%r{//}, '/'); end

        context "without an argument" do
          it "returns #{path}" do
            expect(helper.send(name).to_s).to eq(path)
          end
        end

        context "with an argument" do
          it "adds the argument to the path" do
            expect(helper.send(name, 'foo/bar').to_s).to eq(c("#{path}/foo/bar"))
          end
        end

        context "with a nil argument" do
          it "does not add anything to the path" do
            expect(helper.send(name, nil).to_s).to eq(path)
          end
        end

        context "with installing set to true" do
          before { helper.installing = true}

          it "adds the destdir as prefix" do
            expect(helper.send(name, 'blah').to_s).to eq(c("#{helper.destdir}#{path}/blah"))
          end
        end

        context "with omnibus_installing set to true" do
          before { helper.omnibus_installing = true }

          it "does not add anything to the path" do
            expect(helper.send(name, 'blah').to_s).to eq(c("#{path}/blah"))
          end
        end

        context "with omnibus_installing and installing set to true" do
          before { helper.omnibus_installing = true ; helper.installing = true }

          it "does not add anything to the path" do
            expect(helper.send(name, 'blah').to_s).to eq(c("#{path}/blah"))
          end
        end
      end
    end
  end

  describe "#installing?" do
    context "with installing set to true" do
      before { helper.installing = true}

      it "returns true" do
        expect(helper.installing?).to eq(true)
      end
    end

    context "with installing set to false" do
      before { helper.installing = false }

      it "returns true" do
        expect(helper.installing?).to eq(false)
      end
    end
  end

  describe "#omnibus_installing?" do
    context "with omnibus_installing set to true" do
      before { helper.omnibus_installing = true }

      it "returns true" do
        expect(helper.omnibus_installing?).to eq(true)
      end
    end

    context "with omnibus_installing set to false" do
      before { helper.omnibus_installing = false }

      it "returns false" do
        expect(helper.omnibus_installing?).to eq(false)
      end
    end
  end

  describe "#with_trueprefix" do
    context "with installing set to true" do
      before { helper.installing = true }

      specify "prefix returns /" do
        helper.with_trueprefix do
          expect(helper.prefix.to_s).to eq('/usr')
        end
      end

      it "will restore the previous installing value" do
        helper.with_trueprefix {}
        expect(helper.installing).to eq(true)
      end
    end

    context "with installing set to false" do
      before { helper.installing = false}

      specify "prefix returns /" do
        helper.with_trueprefix do
          expect(helper.prefix.to_s).to eq('/usr')
        end
      end

      it "will restore the previous installing value" do
        helper.with_trueprefix {}
        expect(helper.installing).to eq(false)
      end
    end
  end
end
Something went wrong with that request. Please try again.