aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/language/node_spec.rb
blob: d8d476aebdfb9529c585e30a22bbc46c9c629e16 (plain)
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
require "language/node"

describe Language::Node do
  specify "#npm_cache_config" do
    shutup do
      ret_val = described_class.npm_cache_config
      expect(ret_val).to eq("cache=#{HOMEBREW_CACHE}/npm_cache\n")
    end
  end

  describe "#pack_for_installation" do
    it "raises error with non zero exitstatus" do
      shutup do
        expect { described_class.pack_for_installation }.to raise_error
      end
    end

    it "does not raise error with a zero exitstatus" do
      shutup do
        allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0)
        expect { described_class.pack_for_installation }.not_to raise_error
      end
    end
  end

  describe "#setup_npm_environment" do
    it "npmrc exists" do
      shutup do
        expect(described_class.setup_npm_environment).to be_nil
      end
    end

    it "npmrc does not exist" do
      shutup do
        allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
        described_class.setup_npm_environment
      end
    end
  end

  specify "#std_npm_install_args" do
    shutup do
      npm_install_arg = "libexec"
      allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0)
      resp = described_class.std_npm_install_args npm_install_arg
      expect(resp).to eq(["--verbose", "--global", "--prefix=#{npm_install_arg}", "#{Dir.pwd}/"])
    end
  end

  specify "#local_npm_install_args" do
    shutup do
      resp = described_class.local_npm_install_args
      expect(resp).to eq(["--verbose"])
    end
  end
end