Skip to content

Commit 2d711e1

Browse files
committed
Remove so many nested blocks in the test
The files are already inside a tmpdir, we don't need to delete them after the use.
1 parent ae259e9 commit 2d711e1

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

test/npm_test.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,19 @@ class Importmap::NpmTest < ActiveSupport::TestCase
4848

4949
test "warns (and ignores) vendored packages without version" do
5050
Dir.mktmpdir do |vendor_path|
51-
with_vendored_package(vendor_path, "foo.js") do |foo_path|
52-
with_vendored_package(vendor_path, "baz.js") do |baz_path|
53-
npm = Importmap::Npm.new(file_fixture("import_map_without_cdn_and_versions.rb"), vendor_path: vendor_path)
54-
55-
outdated_packages = []
56-
stdout, _stderr = capture_io { outdated_packages = npm.outdated_packages }
57-
58-
expected = [
59-
"Ignoring foo (#{foo_path}) since no version is specified in the importmap\n",
60-
"Ignoring @bar/baz (#{baz_path}) since no version is specified in the importmap\n"
61-
]
62-
assert_equal(expected, stdout.lines)
63-
assert_equal(0, outdated_packages.size)
64-
end
65-
end
51+
foo_path = create_vendored_file(vendor_path, "foo.js")
52+
baz_path = create_vendored_file(vendor_path, "baz.js")
53+
54+
npm = Importmap::Npm.new(file_fixture("import_map_without_cdn_and_versions.rb"), vendor_path: vendor_path)
55+
56+
outdated_packages = []
57+
stdout, _stderr = capture_io { outdated_packages = npm.outdated_packages }
58+
59+
assert_equal(<<~OUTPUT, stdout)
60+
Ignoring foo (#{foo_path}) since no version is specified in the importmap
61+
Ignoring @bar/baz (#{baz_path}) since no version is specified in the importmap
62+
OUTPUT
63+
assert_equal(0, outdated_packages.size)
6664
end
6765
end
6866

@@ -142,11 +140,9 @@ def code() "200" end
142140
end
143141
end
144142

145-
def with_vendored_package(dir, name)
143+
def create_vendored_file(dir, name)
146144
path = File.join(dir, name)
147145
File.write(path, "console.log(123)")
148-
yield path
149-
ensure
150-
File.delete(path)
146+
path
151147
end
152148
end

0 commit comments

Comments
 (0)