Skip to content

Commit

Permalink
Fixing Unit tests to work under Ruby 1.9.x
Browse files Browse the repository at this point in the history
Suppressed Warning message about RConfig
  • Loading branch information
red-tux committed Nov 1, 2012
1 parent 2a1f44f commit 915dbb2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions api_tests/tc_test_debug.rb
Expand Up @@ -56,23 +56,23 @@ def test_00_debug_10
set_debug_level(1)
debug(1)
end
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:test_00_debug_10:\d+ $/,out.string)
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_10:\d+ $/,out.string)
end

def test_00_debug_15
out = capture_stdout do
set_debug_level(1)
debug(1,:msg=>"none",:var=>"none")
end
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:test_00_debug_15:\d+ none: none$/,out.string)
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_15:\d+ none: none$/,out.string)
end

def test_00_debug_20
out = capture_stdout do
set_debug_level(1)
debug(1,:var=>"Truncation Test",:truncate=>4)
end
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:test_00_debug_20:\d+ Tru \.\.\.\.\. st$/,out.string)
assert_match(/^D1 \.\.\.\/api_tests\/tc_test_debug\.rb:(block in )?test_00_debug_20:\d+ Tru \.\.\.\.\. st$/,out.string)
end

def test_00_debug_25
Expand All @@ -83,7 +83,7 @@ def test_00_debug_25

#puts out.string.length

assert_equal(230,out.string.length,"230 characters are expected from this debug test")
assert(out.string.length>=230,"at least 230 characters are expected from this debug test")
end


Expand Down
5 changes: 4 additions & 1 deletion ts_all_tests.rb
Expand Up @@ -23,7 +23,9 @@
# $Revision$
##########################################

$: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
#$: <<
CURRENT_DIR=File.expand_path(File.join(File.dirname(__FILE__), '.'))
$LOAD_PATH<<CURRENT_DIR
#import variables which describe our local test environment
begin
Expand All @@ -35,6 +37,7 @@
exit(1)
end
require "test/unit"
require "api_tests/tc_test_debug"
require "api_tests/tc_test_user"
Expand Down
25 changes: 17 additions & 8 deletions zbxapi.rb
Expand Up @@ -49,6 +49,12 @@ class ZabbixAPI #create a stub to be defined later
require dir+File.basename(file, File.extname(file))
end

def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end

#------------------------------------------------------------------------------
#
Expand Down Expand Up @@ -118,14 +124,17 @@ def initialize(url,*args)

#Generate the list of sub objects dynamically, from all objects
#derived from ZabbixAPI_Base
objects=Object.constants.map do |i|
obj=Object.const_get(i.intern)
if obj.is_a?(Class) && ([ZabbixAPI_Base]-obj.ancestors).empty?
obj
else
nil
end
end.compact-[ZabbixAPI_Base]
objects=TRUE
silence_warnings do
objects=Object.constants.map do |i|
obj=Object.const_get(i.intern)
if obj.is_a?(Class) && ([ZabbixAPI_Base]-obj.ancestors).empty?
obj
else
nil
end
end.compact-[ZabbixAPI_Base]
end

@objects={}

Expand Down

0 comments on commit 915dbb2

Please sign in to comment.