diff options
| author | Mike McQuaid | 2017-06-30 15:14:32 +0100 |
|---|---|---|
| committer | GitHub | 2017-06-30 15:14:32 +0100 |
| commit | bfe4eed034487b2cc353e8f7b0107fbb00c974d7 (patch) | |
| tree | 10fc94b1337f46a4953ec907b6d173370e53b7f5 /Library/Homebrew/test/language/node_spec.rb | |
| parent | 202b3bc2c1f83b85cbe2cb3d8a5dd19a076d84b4 (diff) | |
| parent | 5e00c277ce45d6af497ec135faf54571c340e704 (diff) | |
| download | brew-bfe4eed034487b2cc353e8f7b0107fbb00c974d7.tar.bz2 | |
Merge pull request #2826 from chrmoritz/languagenode
language/node: multiple improvements
Diffstat (limited to 'Library/Homebrew/test/language/node_spec.rb')
| -rw-r--r-- | Library/Homebrew/test/language/node_spec.rb | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/Library/Homebrew/test/language/node_spec.rb b/Library/Homebrew/test/language/node_spec.rb index b2114bc4f..5ddbde944 100644 --- a/Library/Homebrew/test/language/node_spec.rb +++ b/Library/Homebrew/test/language/node_spec.rb @@ -2,45 +2,56 @@ require "language/node" describe Language::Node do describe "#setup_npm_environment" do - it "does nothing when npmrc exists" do - expect(subject.setup_npm_environment).to be_nil - end - - it "calls prepend_path when node formula exists and npmrc does not exist" do + it "calls prepend_path when node formula exists only during the first call" do node = formula "node" do url "node-test" end stub_formula_loader(node) - allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) expect(ENV).to receive(:prepend_path) - subject.setup_npm_environment + subject.instance_variable_set(:@env_set, false) + expect(subject.setup_npm_environment).to be_nil + + expect(subject.instance_variable_get(:@env_set)).to eq(true) + expect(ENV).not_to receive(:prepend_path) + expect(subject.setup_npm_environment).to be_nil end - it "does not call prepend_path when node formula does not exist but npmrc exists" do - allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) + it "does not call prepend_path when node formula does not exist" do expect(subject.setup_npm_environment).to be_nil end end describe "#std_npm_install_args" do npm_install_arg = "libexec" + npm_pack_cmd = "npm pack --ignore-scripts" it "raises error with non zero exitstatus" do + allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return("error msg") + allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(42) + allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(42) + expect { subject.std_npm_install_args(npm_install_arg) }.to \ + raise_error("npm failed to pack #{Dir.pwd}") + end + + it "raises error with empty npm pack output" do + allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return("") + allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0) + allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(0) expect { subject.std_npm_install_args(npm_install_arg) }.to \ raise_error("npm failed to pack #{Dir.pwd}") end it "does not raise error with a zero exitstatus" do - allow(Utils).to receive(:popen_read).with("npm pack").and_return("pack") + allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return("pack.tgz") allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0) allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(0) resp = subject.std_npm_install_args(npm_install_arg) - expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack") + expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz") end end specify "#local_npm_install_args" do resp = subject.local_npm_install_args - expect(resp).to include("--verbose") + expect(resp).to include("-ddd", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache") end end |
