diff options
| author | Mike McQuaid | 2017-06-24 22:30:47 +0100 |
|---|---|---|
| committer | GitHub | 2017-06-24 22:30:47 +0100 |
| commit | 73d81bb96d550271b3e2e8e62c3c15b99160c15c (patch) | |
| tree | b0a55a3b9d68aab07b16fc58cac074b5281ff6d1 /Library/Homebrew | |
| parent | 5f8a86c17829b9f45486af6a9d24a3aea4bae8b3 (diff) | |
| parent | 67c48360fa61b5f9db36489b84d881ad517e07e6 (diff) | |
| download | brew-73d81bb96d550271b3e2e8e62c3c15b99160c15c.tar.bz2 | |
Merge pull request #2777 from mansimarkaur/inc_test_cov
Added tests for language/node.rb
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/language/node.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/test/language/node_spec.rb | 46 |
2 files changed, 51 insertions, 1 deletions
diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb index 47431e8e5..01d41041b 100644 --- a/Library/Homebrew/language/node.rb +++ b/Library/Homebrew/language/node.rb @@ -25,7 +25,11 @@ module Language npmrc.write npm_cache_config # explicitly use our npm and node-gyp executables instead of the user # managed ones in HOMEBREW_PREFIX/lib/node_modules which might be broken - ENV.prepend_path "PATH", Formula["node"].opt_libexec/"bin" + begin + ENV.prepend_path "PATH", Formula["node"].opt_libexec/"bin" + rescue FormulaUnavailableError + nil + end end def self.std_npm_install_args(libexec) diff --git a/Library/Homebrew/test/language/node_spec.rb b/Library/Homebrew/test/language/node_spec.rb new file mode 100644 index 000000000..b2114bc4f --- /dev/null +++ b/Library/Homebrew/test/language/node_spec.rb @@ -0,0 +1,46 @@ +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 + 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 + 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) + expect(subject.setup_npm_environment).to be_nil + end + end + + describe "#std_npm_install_args" do + npm_install_arg = "libexec" + + it "raises error with non zero exitstatus" do + 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_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") + end + end + + specify "#local_npm_install_args" do + resp = subject.local_npm_install_args + expect(resp).to include("--verbose") + end +end |
