[SCM] ci-tooling packaging branch, master, updated. 697d07461388f26c46fbbd30414ccbbe0a8eb794

Harald Sitter apachelogger-guest at moszumanska.debian.org
Thu Mar 5 13:16:28 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=f446467

The following commit has been merged in the master branch:
commit f4464679b7395b3ed02c6025795d6c0f37aa1fcc
Author: Harald Sitter <sitter at kde.org>
Date:   Thu Mar 5 12:40:15 2015 +0100

    split assert_system functionality into separate module for prepending
---
 test/lib/assert_system.rb | 33 +++++++++++++++++++++++++++++++++
 test/test_apt.rb          | 24 +++---------------------
 2 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/test/lib/assert_system.rb b/test/lib/assert_system.rb
new file mode 100644
index 0000000..096c4a1
--- /dev/null
+++ b/test/lib/assert_system.rb
@@ -0,0 +1,33 @@
+# Prependable module enabling assert_system use by overriding Kernel.system
+module AssertSystem
+  module_function
+
+  # TestUnit prepend to force alias diversion making #{Kernel.system} noop
+  def setup
+    Kernel.send(:alias_method, :system_setup, :system)
+    Kernel.send(:define_method, :system) { |*_a| }
+  end
+
+  # TestUnit prepend to remove alias diversion making #{Kernel.system} noop
+  def teardown
+    Kernel.send(:alias_method, :system, :system_setup)
+    Kernel.send(:undef_method, :system_setup)
+  end
+
+  # Assert that a specific system call is made. The call itself is not made.
+  # @param args [Object] any suitable input of #{Kernel.system} that is expected
+  # @param block [Block] this function yields to block to actually run a
+  #   piece of code that is expected to cause the system call
+  # @return [Object] return value of block
+  def assert_system(args, &block)
+    assertee = self
+    Kernel.send(:alias_method, :system_orig, :system)
+    Kernel.send(:define_method, :system) do |*a|
+      assertee.assert_equal([*args], [*a])
+    end
+    block.yield
+  ensure
+    Kernel.send(:alias_method, :system, :system_orig)
+    Kernel.send(:undef_method, :system_orig)
+  end
+end
diff --git a/test/test_apt.rb b/test/test_apt.rb
index 545785b..360500c 100644
--- a/test/test_apt.rb
+++ b/test/test_apt.rb
@@ -2,29 +2,11 @@ require 'test/unit'
 
 require_relative '../lib/apt'
 
+require_relative 'lib/assert_system'
+
 # Test Apt
 class AptTest < Test::Unit::TestCase
-  def setup
-    Kernel.send(:alias_method, :system_setup, :system)
-    Kernel.send(:define_method, :system) { |*_a| }
-  end
-
-  def teardown
-    Kernel.send(:alias_method, :system, :system_setup)
-    Kernel.send(:undef_method, :system_setup)
-  end
-
-  def assert_system(args, &block)
-    assertee = self
-    Kernel.send(:alias_method, :system_orig, :system)
-    Kernel.send(:define_method, :system) do |*a|
-      assertee.assert_equal([*args], [*a])
-    end
-    block.yield
-  ensure
-    Kernel.send(:alias_method, :system, :system_orig)
-    Kernel.send(:undef_method, :system_orig)
-  end
+  prepend AssertSystem
 
   def test_repo
     repo = Apt::Repository.new('ppa:yolo')

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list