From 5a5879c51afc128ea723443de26458ebdc645c6a Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 5 Dec 2012 01:02:39 -0800 Subject: fixed problems with ruby 1.8 and GLI, and added some tests. --- test/test_helper.rb | 32 +++++++++++++++++++++++++++++++- test/unit/command_line_test.rb | 12 ++++++++++++ test/unit/config_object_list_test.rb | 2 +- test/unit/config_object_test.rb | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/unit/command_line_test.rb (limited to 'test') diff --git a/test/test_helper.rb b/test/test_helper.rb index e761086..94bb2b4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,16 +4,46 @@ require 'minitest/autorun' require 'leap_cli' class MiniTest::Unit::TestCase + attr_accessor :ruby_path # Add global extensions to the test case class here + def setup + LeapCli::Path.set_platform_path(test_platform_path) + LeapCli::Path.set_provider_path(test_provider_path) + end + def manager @manager ||= begin - LeapCli::Path.set_root(File.dirname(__FILE__)) manager = LeapCli::Config::Manager.new manager.load manager end end + def base_path + File.expand_path '../..', __FILE__ + end + + def leap_bin(*args) + `#{ruby_path} #{base_path}/bin/leap #{args.join ' '}` + end + + def test_platform_path + "#{base_path}/test/leap_platform" + end + + def test_provider_path + "#{base_path}/test/provider" + end + + def with_multiple_rubies(&block) + ['ruby1.8', 'ruby1.9.1'].each do |ruby| + self.ruby_path = `which #{ruby}`.strip + next unless ruby_path.chars.any? + yield + end + self.ruby_path = "" + end + end diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb new file mode 100644 index 0000000..ec4c2d6 --- /dev/null +++ b/test/unit/command_line_test.rb @@ -0,0 +1,12 @@ +require File.expand_path('test_helper', File.dirname(__FILE__)) + +class CommandLineTest < MiniTest::Unit::TestCase + + def test_help + with_multiple_rubies do + output = leap_bin('help') + assert_equal 0, $?, "help should exit 0 -- #{output}" + end + end + +end diff --git a/test/unit/config_object_list_test.rb b/test/unit/config_object_list_test.rb index a3b76f2..a507094 100644 --- a/test/unit/config_object_list_test.rb +++ b/test/unit/config_object_list_test.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/test_helper' -class TestMeme < MiniTest::Unit::TestCase +class ConfigObjectListTest < MiniTest::Unit::TestCase def test_node_search nodes = manager.nodes['name' => 'vpn1'] diff --git a/test/unit/config_object_test.rb b/test/unit/config_object_test.rb index 0c293c2..b981f3b 100644 --- a/test/unit/config_object_test.rb +++ b/test/unit/config_object_test.rb @@ -1,6 +1,6 @@ require File.expand_path('test_helper', File.dirname(__FILE__)) -class TestMeme < MiniTest::Unit::TestCase +class ConfigObjectTest < MiniTest::Unit::TestCase def test_bracket_lookup domain = manager.provider.domain -- cgit v1.2.3