From fe7155419ee3d3c198ce80158f80e7d44b9b5f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 15 Apr 2014 19:02:02 +0200 Subject: [PATCH] Improve temporary patch file usage and tests --- lib/hub/commands.rb | 4 +++- test/hub_test.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 4b555291..5a000819 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -1,3 +1,5 @@ +require 'tempfile' + module Hub # The Commands module houses the git commands that hub # lovingly wraps. If a method exists here, it is expected to have a @@ -519,7 +521,7 @@ module Hub end end - patch_file = Tempfile.new('patch_name') + patch_file = Tempfile.new(patch_name).path File.open(patch_file, 'w') { |file| file.write(patch) } args[idx] = patch_file end diff --git a/test/hub_test.rb b/test/hub_test.rb index b3ce02d3..b4346c6d 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -171,7 +171,7 @@ class HubTest < Minitest::Test to_return(:status => 200) with_tmpdir('/tmp/') do - assert_commands "git am --signoff /tmp/55.patch -p2", + assert_commands %r{git am --signoff /tmp/55\.patch[\w-]+ -p2}, "am --signoff https://github.com/defunkt/hub/pull/55#comment_123 -p2" cmd = Hub("am https://github.com/defunkt/hub/pull/55/files").command @@ -196,7 +196,7 @@ class HubTest < Minitest::Test with_tmpdir('/tmp/') do url = 'https://github.com/davidbalbert/hub/commit/fdb9921' - assert_commands "git am --signoff /tmp/fdb9921.patch -p2", + assert_commands %r{git am --signoff /tmp/fdb9921\.patch[\w-]+ -p2}, "am --signoff #{url} -p2" end end @@ -217,7 +217,7 @@ class HubTest < Minitest::Test with_tmpdir('/tmp/') do url = 'https://gist.github.com/8da7fb575debd88c54cf' - assert_commands "git am --signoff /tmp/gist-8da7fb575debd88c54cf.txt -p2", + assert_commands %r{git am --signoff /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2}, "am --signoff #{url} -p2" end end @@ -231,7 +231,7 @@ class HubTest < Minitest::Test to_return(:status => 200) with_tmpdir('/tmp/') do - assert_commands "git apply /tmp/55.patch -p2", + assert_commands %r{git apply /tmp/55\.patch[\w-]+ -p2}, "apply https://github.com/defunkt/hub/pull/55 -p2" cmd = Hub("apply https://github.com/defunkt/hub/pull/55/files").command @@ -246,7 +246,7 @@ class HubTest < Minitest::Test with_tmpdir('/tmp/') do url = 'https://github.com/davidbalbert/hub/commit/fdb9921' - assert_commands "git apply /tmp/fdb9921.patch -p2", + assert_commands %r{git apply /tmp/fdb9921\.patch[\w-]+ -p2}, "apply #{url} -p2" end end @@ -266,7 +266,7 @@ class HubTest < Minitest::Test with_tmpdir('/tmp/') do url = 'https://gist.github.com/mislav/8da7fb575debd88c54cf' - assert_commands "git apply /tmp/gist-8da7fb575debd88c54cf.txt -p2", + assert_commands %r{git apply /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2}, "apply #{url} -p2" end end -- GitLab