File: directory_maker_spec.rb

package info (click to toggle)
ruby-rspec 3.9.0c2e2m1s3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,612 kB
  • sloc: ruby: 67,456; sh: 1,572; makefile: 98
file content (60 lines) | stat: -rw-r--r-- 1,752 bytes parent folder | download | duplicates (4)
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
require "spec_helper"
require "fileutils"

RSpec::Support.require_rspec_support("directory_maker")

module RSpec::Support
  describe DirectoryMaker do
    shared_examples_for "an mkdir_p implementation" do
      include_context "isolated directory"

      let(:dirname) { File.join(%w[tmp a recursive structure]) }

      def directory_exists?(dirname)
        File.exist?(dirname) && File.directory?(dirname)
      end

      it "makes directories recursively" do
        mkdir_p.call(dirname)
        expect(directory_exists?(dirname)).to be true
      end

      it "does not raise if the directory already exists" do
        Dir.mkdir("tmp")
        mkdir_p.call(dirname)
        expect(directory_exists?(dirname)).to be true
      end

      context "when a file already exists" do
        before { File.open("tmp", "w") }

        it "raises, as it can't make the directory", :failing_on_appveyor,
           :pending => false,
           :skip => (ENV['APPVEYOR'] ? "Failing on AppVeyor but :pending isn't working for some reason" : false) do
          expect {
            mkdir_p.call(dirname)
          }.to raise_error(Errno::EEXIST)
        end
      end

      context "when the path specified is absolute" do
        let(:dirname) { "bees/ponies" }

        it "makes directories recursively" do
          mkdir_p.call(File.expand_path(dirname))
          expect(directory_exists?(dirname)).to be true
        end
      end
    end

    describe ".mkdir_p" do
      subject(:mkdir_p) { DirectoryMaker.method(:mkdir_p) }
      it_behaves_like "an mkdir_p implementation"
    end

    describe "FileUtils.mkdir_p" do
      subject(:mkdir_p) { FileUtils.method(:mkdir_p) }
      it_behaves_like "an mkdir_p implementation"
    end
  end
end