[Libguestfs] [PATCH 2/2] ruby: tests: use more asserts instead of manual checks

Pino Toscano ptoscano at redhat.com
Tue Feb 23 10:51:51 UTC 2016


Make more use of assert_equal/refute_equal instead of manually checking
values and raising errors.
---
 ruby/t/tc_100_launch.rb       | 4 +---
 ruby/t/tc_410_close_event.rb  | 8 ++------
 ruby/t/tc_420_log_messages.rb | 4 +---
 ruby/t/tc_810_rhbz664558c6.rb | 4 +---
 4 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/ruby/t/tc_100_launch.rb b/ruby/t/tc_100_launch.rb
index 9c31aa5..b79b984 100644
--- a/ruby/t/tc_100_launch.rb
+++ b/ruby/t/tc_100_launch.rb
@@ -30,9 +30,7 @@ class TestLoad < MiniTest::Unit::TestCase
     g.lvcreate("LV2", "VG", 200);
 
     lvs = g.lvs()
-    if lvs != ["/dev/VG/LV1", "/dev/VG/LV2"]
-      raise "incorrect lvs returned"
-    end
+    assert_equal ["/dev/VG/LV1", "/dev/VG/LV2"], lvs
 
     g.sync()
   end
diff --git a/ruby/t/tc_410_close_event.rb b/ruby/t/tc_410_close_event.rb
index c547613..be62b91 100644
--- a/ruby/t/tc_410_close_event.rb
+++ b/ruby/t/tc_410_close_event.rb
@@ -29,12 +29,8 @@ class TestLoad < MiniTest::Unit::TestCase
     # Check that the close event is called.
     g.set_event_callback(close, Guestfs::EVENT_CLOSE)
 
-    if close_invoked != 0
-      raise "close_invoked should be 0"
-    end
+    assert_equal 0, close_invoked
     g.close()
-    if close_invoked != 1
-      raise "close_invoked should be 1"
-    end
+    assert_equal 1, close_invoked
   end
 end
diff --git a/ruby/t/tc_420_log_messages.rb b/ruby/t/tc_420_log_messages.rb
index 90a1360..e64ea74 100644
--- a/ruby/t/tc_420_log_messages.rb
+++ b/ruby/t/tc_420_log_messages.rb
@@ -45,8 +45,6 @@ class TestLoad < MiniTest::Unit::TestCase
     g.set_autosync(1)
 
     g.close()
-    if log_invoked == 0
-      raise "log_invoked should be > 0"
-    end
+    refute_equal 0, log_invoked
   end
 end
diff --git a/ruby/t/tc_810_rhbz664558c6.rb b/ruby/t/tc_810_rhbz664558c6.rb
index 7e27db2..347e403 100644
--- a/ruby/t/tc_810_rhbz664558c6.rb
+++ b/ruby/t/tc_810_rhbz664558c6.rb
@@ -38,8 +38,6 @@ class TestLoad < MiniTest::Unit::TestCase
     # This should call the close callback.
     g.close()
 
-    if close_invoked != 1
-      raise "close_invoked should be 1"
-    end
+    assert_equal 1, close_invoked
   end
 end
-- 
2.5.0




More information about the Libguestfs mailing list