refactored Ruby version tokens handling

This commit is contained in:
Colin Surprenant 2012-06-28 13:19:03 -04:00
parent 48007e519c
commit a988abd1b9
3 changed files with 38 additions and 3 deletions

View File

@ -22,7 +22,12 @@ module RedStorm
$1
end
module_function :current_ruby_mode
def jruby_mode_token(ruby_version = nil)
version_map = {"1.8" => "RUBY1_8", "--1.8" => "RUBY1_8", "1.9" => "RUBY1_9", "--1.9" => "RUBY1_9"}
version_map[ruby_version.to_s] || version_map[RedStorm.current_ruby_mode]
end
module_function :current_ruby_mode, :jruby_mode_token
# puts("*** LAUNCH_PATH=#{LAUNCH_PATH}")
# puts("*** JAR_CONTEXT=#{JAR_CONTEXT}")

View File

@ -29,8 +29,7 @@ end
task :launch, :env, :ruby_mode, :class_file do |t, args|
# use ruby mode parameter or default to current interpreter version
version_map = {"--1.8" => "RUBY1_8", "--1.9" => "RUBY1_9"}
version_token = version_map[args[:ruby_mode] || "--#{RedStorm.current_ruby_mode}"]
version_token = RedStorm.jruby_mode_token(args[:ruby_mode])
command = case args[:env]
when "local"

View File

@ -0,0 +1,31 @@
require 'spec_helper'
require 'red_storm/environment'
describe RedStorm do
describe "jruby_mode_token" do
it "should default to current JRuby mode" do
RedStorm.should_receive(:current_ruby_mode).and_return("1.8")
RedStorm.jruby_mode_token.should == "RUBY1_8"
RedStorm.should_receive(:current_ruby_mode).and_return("1.9")
RedStorm.jruby_mode_token.should == "RUBY1_9"
end
it "should use provided version" do
RedStorm.should_receive(:current_ruby_mode).never
RedStorm.jruby_mode_token("1.8").should == "RUBY1_8"
RedStorm.jruby_mode_token("--1.8").should == "RUBY1_8"
RedStorm.jruby_mode_token("1.9").should == "RUBY1_9"
RedStorm.jruby_mode_token("--1.9").should == "RUBY1_9"
end
it "should default to current JRuby mode on invalid version" do
RedStorm.should_receive(:current_ruby_mode).and_return("1.9")
RedStorm.jruby_mode_token("foobar").should == "RUBY1_9"
end
end
end