in rake-runner-test/src/jetbrains/slow/plugins/rakerunner/RubyEnvConfiguratorServiceAgentTest.java [321:434]
public void test_RvmSdk_EnvSettings() throws Exception {
if (!SystemInfo.isUnix) {
// TODO: use mocks
throw new SkipException("Not a UNIX. RVM support is only for Unix.");
}
final Ref<Map<String, String>> allParamsRef = new Ref<Map<String, String>>();
final Ref<Map<String, String>> envParamsRef = new Ref<Map<String, String>>();
final Ref<Map<String, String>> sysPropertiesRef = new Ref<Map<String, String>>();
// add listener
addBuildParamsListener(envParamsRef, sysPropertiesRef, allParamsRef, null);
final HashMap<String, String> featureParamsMap = new HashMap<String, String>();
// use rvm
//final String rvmRubyName = myRubyVersion != null ? myRubyVersion : System.getProperty(RAKE_RUNNER_TESTING_RUBY_VERSION_PROPERTY);
final String rvmRubyName = RubyVersionsDataProvider.getExistentRVMRubyVersion();
final String rvmGemsetName = "teamcity";
featureParamsMap.put(RubyEnvConfiguratorConstants.UI_USE_RVM_KEY, "manual");
featureParamsMap.put(RubyEnvConfiguratorConstants.UI_RVM_SDK_NAME_KEY, rvmRubyName);
featureParamsMap.put(RubyEnvConfiguratorConstants.UI_RVM_GEMSET_NAME_KEY, rvmGemsetName);
featureParamsMap.put(RubyEnvConfiguratorConstants.UI_RVM_GEMSET_CREATE_IF_NON_EXISTS, "true");
final SBuildType bt = configureFakeBuild(FakeBuildConfiguration.Feature, featureParamsMap);
SBuild build = startBuild(bt, false);
build = finishBuild(build);
dumpBuildLog(build);
final Map<String, String> envs = envParamsRef.get();
Assert.assertNotNull(envs);
Assert.assertNotNull(allParamsRef.get());
RVMPathsSettings.getInstanceEx().initialize(envParamsRef.get());
assertNotNull(RVMPathsSettings.getInstance());
final InstalledRVM rvm = RVMPathsSettings.getInstance().getRVM();
assertNotNull("RVM found", rvm);
final String rvmHomePath = rvm.getPath();
Assert.assertNotNull(rvmHomePath, "Cannot retrieve RVM home path");
// Ensure new gemset created
final Pair<String, String> detected = RVMSupportUtil.determineSuitableRVMSdkDist(rvmRubyName, rvmGemsetName);
Assert.assertNotNull(detected);
Assert.assertNotNull(detected.first, "RVM should have interpreter " + rvmRubyName);
Assert.assertNotNull(detected.second, "RVM should have gemset '" + rvmGemsetName + "' for interpreter " + rvmRubyName);
// Use some regex
final String regexRuby = "[^/]*" + rvmRubyName + "[^/@]*";
final String regexRubyAndGemset = regexRuby + "@" + rvmGemsetName;
final String regexRubyAndGlobal = regexRuby + "@global";
final String envGemPath = envs.get("GEM_PATH");
{
Assert.assertNotNull(envGemPath, "GEM_PATH not set");
final String[] paths = envGemPath.split(File.pathSeparator);
CommonAsserts.then(paths).hasSize(2);
System.out.println("GEM_PATH: " + Arrays.toString(paths));
CommonAsserts.then(paths[0]).matches(rvmHomePath + "/gems/" + regexRubyAndGemset);
CommonAsserts.then(paths[1]).matches(rvmHomePath + "/gems/" + regexRubyAndGlobal);
}
final String envGemHome = envs.get("GEM_HOME");
{
CommonAsserts.then(envGemHome).matches(rvmHomePath + "/gems/" + regexRubyAndGemset);
}
final String envPath = envs.get("PATH");
{
Assert.assertNotNull(envPath, "PATH not set");
final String[] paths = envPath.split(File.pathSeparator);
Assert.assertTrue(paths.length >= 4);
System.out.println("PATH[0-4]: " + Arrays.asList(paths).subList(0, 4));
CommonAsserts.then(paths[0]).matches(rvmHomePath + "/gems/" + regexRubyAndGemset + "/bin");
CommonAsserts.then(paths[1]).matches(rvmHomePath + "/gems/" + regexRubyAndGlobal + "/bin");
CommonAsserts.then(paths[2]).matches(rvmHomePath + "/rubies/" + regexRuby + "/bin");
CommonAsserts.then(paths[3]).isEqualTo(rvmHomePath + "/bin");
}
final String envMyRubyHome = envs.get("MY_RUBY_HOME");
{
CommonAsserts.then(envMyRubyHome).isNotNull().matches(rvmHomePath + "/rubies/" + regexRuby);
}
// final String envBundlePath = envs.get("BUNDLE_PATH");
// {
// Assert.assertNotNull(envBundlePath);
// Assert.assertTrue(envBundlePath.matches(rvmHomePath + "/gems/" + regexRubyAndGemset));
// }
final String envRVMRubyString = envs.get("rvm_ruby_string");
{
CommonAsserts.then(envRVMRubyString).isNotNull().matches(regexRuby);
}
// Assert.assertEquals(envs.get("GEM_PATH"), rvmHomePath + "/gems/ruby-1.8.7-p249@teamcity:"
// + rvmHomePath + "/gems/ruby-1.8.7-p249@global");
// Assert.assertEquals(envs.get("GEM_HOME"), rvmHomePath + "/gems/ruby-1.8.7-p249@teamcity");
// Assert.assertTrue(envs.get("PATH").startsWith(rvmHomePath + "/rubies/ruby-1.8.7-p249/bin:" +
// rvmHomePath + "/gems/ruby-1.8.7-p249@teamcity/bin:" +
// rvmHomePath + "/gems/ruby-1.8.7-p249@global/bin:" +
// rvmHomePath + "/bin"));
// Assert.assertEquals(envs.get("MY_RUBY_HOME"), rvmHomePath + "/rubies/ruby-1.8.7-p249");
// Assert.assertEquals(envs.get("BUNDLE_PATH"), rvmHomePath + "/gems/ruby-1.8.7-p249@teamcity");
// Assert.assertEquals(envs.get("rvm_ruby_string"), "ruby-1.8.7-p249");
// successfully finished
assertSuccessful(build);
}