Improved test quality
This commit is contained in:
parent
cf5db0e0df
commit
2cb678a6d5
@ -1,56 +1,36 @@
|
||||
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")
|
||||
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 npmrc does not exist" do
|
||||
allow(Formula).to receive(:[]).with("node").and_return(formula { url "foo-1.0" })
|
||||
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
|
||||
allow(ENV).to receive(:prepend_path).with("PATH", Formula["node"].opt_libexec/"bin").and_return("prepend_path called")
|
||||
expect(subject.setup_npm_environment).to eq("prepend_path called")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#pack_for_installation" do
|
||||
describe "#std_npm_install_args" do
|
||||
npm_install_arg = "libexec"
|
||||
|
||||
it "raises error with non zero exitstatus" do
|
||||
shutup do
|
||||
expect { described_class.pack_for_installation }.to raise_error
|
||||
end
|
||||
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
|
||||
shutup 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)
|
||||
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}/"])
|
||||
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
|
||||
shutup do
|
||||
resp = described_class.local_npm_install_args
|
||||
expect(resp).to eq(["--verbose"])
|
||||
end
|
||||
resp = subject.local_npm_install_args
|
||||
expect(resp).to include("--verbose")
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user