spec/aruba/jruby_spec.rb in aruba-0.14.9 vs spec/aruba/jruby_spec.rb in aruba-0.14.10

- old
+ new

@@ -1,55 +1,73 @@ require 'spec_helper' require 'aruba/api' describe "Aruba JRuby Startup Helper" do - before(:all) do - @fake_env = ENV.clone + include Aruba::Api + + let(:rb_config) { double('RbConfig::CONFIG') } + let(:command) do + instance_double(Aruba::Processes::BasicProcess, :environment => command_environment) end + let(:command_environment) { { 'JRUBY_OPTS' => '--1.9', 'JAVA_OPTS' => '-Xdebug' } } - before :each do + before do Aruba.config.reset - # Define before_cmd-hook + # Define before :command hook load 'aruba/config/jruby.rb' end - before(:each) do - @fake_env['JRUBY_OPTS'] = "--1.9" - @fake_env['JAVA_OPTS'] = "-Xdebug" - - stub_const('ENV', @fake_env) - end - - context 'when some mri ruby' do - before :each do + context 'when running under some MRI Ruby' do + before do stub_const('RUBY_PLATFORM', 'x86_64-chocolate') end - before :each do - Aruba.config.before :command, self - end + it 'keeps the existing JRUBY_OPTS and JAVA_OPTS environment values' do + # Run defined before :command hook + Aruba.config.before :command, self, command - it { expect(ENV['JRUBY_OPTS']).to eq '--1.9' } - it { expect(ENV['JAVA_OPTS']).to eq '-Xdebug' } + aggregate_failures do + expect(command_environment['JRUBY_OPTS']).to eq '--1.9' + expect(command_environment['JAVA_OPTS']).to eq '-Xdebug' + end + end end - context 'when jruby ruby' do - before :each do - stub_const('RUBY_PLATFORM', 'java') + context 'when running under JRuby but not on Solaris' do + before do + stub_const 'RUBY_PLATFORM', 'java' + stub_const 'RbConfig::CONFIG', rb_config + + allow(rb_config).to receive(:[]).with('host_os').and_return('foo-os') end - before :each do - rb_config = double('rb_config') - allow(rb_config).to receive(:[]).and_return('solaris') + it 'updates the existing JRuby but not Java option values' do + # Run defined before :command hook + Aruba.config.before :command, self, command - stub_const 'RbConfig::CONFIG', rb_config + aggregate_failures do + expect(command_environment['JRUBY_OPTS']).to eq '--dev -X-C --1.9' + expect(command_environment['JAVA_OPTS']).to eq '-Xdebug' + end end + end + context 'when running under JRuby on Solaris' do before :each do - Aruba.config.before :command, self + stub_const 'RUBY_PLATFORM', 'java' + stub_const 'RbConfig::CONFIG', rb_config + + allow(rb_config).to receive(:[]).with('host_os').and_return('solaris') end - it { expect(ENV['JRUBY_OPTS']).to eq '--dev -X-C --1.9' } - it { expect(ENV['JAVA_OPTS']).to eq '-d32 -Xdebug' } + it 'keeps the existing JRuby and Java option values' do + # Run defined before :command hook + Aruba.config.before :command, self, command + + aggregate_failures do + expect(command_environment['JRUBY_OPTS']).to eq '--dev -X-C --1.9' + expect(command_environment['JAVA_OPTS']).to eq '-d32 -Xdebug' + end + end end end