You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/08/11 03:03:25 UTC

[PATCH 4/6] * tests/helpers/common.rb: add a assert_uri assertion

From: David Lutterkort <lu...@redhat.com>

We deal with lots of URI's and need a way to check they are valid
---
 tests/helpers/common.rb |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/tests/helpers/common.rb b/tests/helpers/common.rb
index 5b3bcfb..fd627a2 100644
--- a/tests/helpers/common.rb
+++ b/tests/helpers/common.rb
@@ -67,3 +67,20 @@ module Deltacloud
     end
   end
 end
+
+# Add an assertion for URI's
+module MiniTest::Assertions
+  def assert_uri(obj, msg = nil)
+    msg = message(msg) { "Expected #{mu_pp(obj)} to be a valid URI" }
+    refute_nil obj, msg
+    refute_empty obj, msg
+    begin
+      u = URI.parse(obj)
+      refute_nil u.path, msg
+    rescue => e
+      fail "Could not parse URI #{mu_pp(obj)}"
+    end
+  end
+end
+
+MiniTest::Expectations::infect_an_assertion :assert_uri, :must_be_uri, :unary
-- 
1.7.7.6