Improved kitchen methods in Ruby file

Change-Id: I7cdc5eebcceffcb212b77171d28629a7ebf809d8
diff --git a/src/com/mirantis/mk/Ruby.groovy b/src/com/mirantis/mk/Ruby.groovy
index 4d94276..fa7c0ea 100644
--- a/src/com/mirantis/mk/Ruby.groovy
+++ b/src/com/mirantis/mk/Ruby.groovy
@@ -4,22 +4,37 @@
  * Ruby functions
  */
 
-def ensureRubyEnv(rubyVersion="2.4.0"){
-    sh """rbenv install ${rubyVersion};
-          rbenv local ${rubyVersion};
-          rbenv exec gem update --system"""
+/**
+ * Ensures Ruby environment with given version (install it if necessary)
+ * @param rubyVersion target ruby version (optional, default 2.3.2)
+ */
+def ensureRubyEnv(rubyVersion="2.3.2"){
+    if(!fileExists("/var/lib/jenkins/.rbenv/versions/${rubyVersion}/bin/ruby")){
+        sh "rbenv install ${rubyVersion}";
+    }
+    sh "rbenv local ${rubyVersion};rbenv exec gem update --system"
 }
+
+/**
+ * Install kitchen tools
+ */
 def installKitchen(){
     sh """rbenv exec gem install bundler;
           rbenv exec gem install test-kitchen"""
 }
 
+/**
+ * Run kitchen tests in tests/integration
+ */
 def runKitchenTests(){
     runKitchenCommand("converge")
     runKitchenCommand("verify -t tests/integration")
 }
 
-
+/**
+ * Run kitchen command
+ * @param cmd kitchen command
+ */
 def runKitchenCommand(cmd){
     sh "rbenv exec bundler exec kitchen ${cmd}"
 }