diff --git a/lib/red_storm/environment.rb b/lib/red_storm/environment.rb index 5f40733..d064687 100644 --- a/lib/red_storm/environment.rb +++ b/lib/red_storm/environment.rb @@ -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}") diff --git a/lib/tasks/red_storm.rake b/lib/tasks/red_storm.rake index fcd825c..de34fec 100644 --- a/lib/tasks/red_storm.rake +++ b/lib/tasks/red_storm.rake @@ -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" diff --git a/spec/red_storm/environment_spec.rb b/spec/red_storm/environment_spec.rb new file mode 100644 index 0000000..ca6c625 --- /dev/null +++ b/spec/red_storm/environment_spec.rb @@ -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