Skip to content

Commit

Permalink
test: make it a bit easier to debug package manager cases
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Aug 19, 2023
1 parent db46a1f commit 6c0e481
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
7 changes: 1 addition & 6 deletions spec/package_json/managers/npm_like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

around { |example| within_temp_directory { example.run } }

before do
allow(Kernel).to receive(:system).and_wrap_original do |original_method, *args|
# make things quieter by redirecting output to /dev/null
original_method.call(*args, 1 => File::NULL, 2 => File::NULL)
end
end
before { allow_kernel_to_receive_system }

describe "#install" do
it "runs and returns true" do
Expand Down
7 changes: 1 addition & 6 deletions spec/package_json/managers/pnpm_like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

around { |example| within_temp_directory { example.run } }

before do
allow(Kernel).to receive(:system).and_wrap_original do |original_method, *args|
# make things quieter by redirecting output to /dev/null
original_method.call(*args, 1 => File::NULL, 2 => File::NULL)
end
end
before { allow_kernel_to_receive_system }

describe "#install" do
it "runs and returns true" do
Expand Down
7 changes: 1 addition & 6 deletions spec/package_json/managers/yarn_classic_like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

around { |example| within_temp_directory { example.run } }

before do
allow(Kernel).to receive(:system).and_wrap_original do |original_method, *args|
# make things quieter by redirecting output to /dev/null
original_method.call(*args, 1 => File::NULL, 2 => File::NULL)
end
end
before { allow_kernel_to_receive_system }

describe "#install" do
it "runs and returns true" do
Expand Down
13 changes: 13 additions & 0 deletions spec/support/expect_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
require "json"

def allow_kernel_to_receive_system
allow(Kernel).to receive(:system).and_wrap_original do |original_method, *args|
# :nocov:
if ENV.fetch("PACKAGE_JSON_DEBUG", "false").downcase == "true"
original_method.call(*args)
else
# make things quieter by redirecting output to /dev/null
original_method.call(*args, 1 => File::NULL, 2 => File::NULL)
end
# :nocov:
end
end

def expect_package_json_with_content(content)
expect(File.exist?("package.json")).to be(true)

Expand Down

0 comments on commit 6c0e481

Please sign in to comment.