diff --git a/lib/chili_project/database.rb b/lib/chili_project/database.rb
index 3c03036826b3fe0f0fac2d63a437211e92a1d093..672052ff531a121cf78a0841e316bd752645aec4 100644
--- a/lib/chili_project/database.rb
+++ b/lib/chili_project/database.rb
@@ -66,7 +66,7 @@ module ChiliProject
         version = ActiveRecord::Base.connection.select_value('SELECT version()')
         raw ? version : version.match(/^PostgreSQL (\S+)/i)[1]
       when :sqlite
-        if RUBY_ENGINE == 'jruby'
+        if Object.const_defined?('RUBY_ENGINE') && ::RUBY_ENGINE == 'jruby'
           Jdbc::SQLite3::VERSION
         else
           if SQLite3.const_defined? 'SQLITE_VERSION'
diff --git a/test/unit/lib/chili_project/database_test.rb b/test/unit/lib/chili_project/database_test.rb
index 16253729dfb2f3036bd1f9d359c31acc03cfe072..9908737ee207391f06729a046b6e57a43e537681 100644
--- a/test/unit/lib/chili_project/database_test.rb
+++ b/test/unit/lib/chili_project/database_test.rb
@@ -36,7 +36,7 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
     begin
       ChiliProject::Database.stubs(:adapter_name).returns "SQLite"
 
-      if RUBY_ENGINE == 'jruby'
+      if Object.const_defined?('RUBY_ENGINE') && ::RUBY_ENGINE == 'jruby'
         # If we have the SQLite3 gem installed, save the old constant
         if Object.const_defined?('Jdbc') && Jdbc::SQLite3.const_defined?('SQLite3')
           sqlite3_version = Jdbc::SQLite3::VERSION
@@ -70,7 +70,7 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
       assert_equal "1.2.3", ChiliProject::Database.version(true)
     ensure
       # Clean up after us
-      if RUBY_ENGINE == 'jruby'
+      if Object.const_defined?('RUBY_ENGINE') && ::RUBY_ENGINE == 'jruby'
         if created_module
           Jdbc.instance_eval{remove_const 'SQLite3' }
         elsif sqlite3_version