Skip to content

Commit 4485f15

Browse files
committed
fixed bug when executing single suite outside koans dir
1 parent c40b41b commit 4485f15

6 files changed

Lines changed: 24 additions & 25 deletions

File tree

‎koans-lib/src/com/sandwich/koan/path/xmltransformation/RbVariableInjector.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.sandwich.koan.path.xmltransformation;
22

3-
import java.io.File;
43
import java.lang.reflect.Method;
54

65
import com.sandwich.koan.constant.KoanConstants;
76
import com.sandwich.util.Strings;
7+
import com.sandwich.util.io.FileUtils;
8+
import com.sandwich.util.io.directories.DirectoryManager;
89

910
public class RbVariableInjector {
1011

@@ -28,8 +29,8 @@ public RbVariableInjector(String lesson, Method koanMethod){
2829
this.lesson = lesson;
2930
methodName = koanMethod.getName();
3031
suiteName = declaringClass.getSimpleName();
31-
suitePath = new File("src/"+declaringClass.getName().replace('.', '/')).getAbsolutePath()
32-
.replace(koanMethod.getDeclaringClass().getSimpleName(), "");
32+
String path = FileUtils.getSourceFileFromClass(declaringClass.getName()).getAbsolutePath();
33+
suitePath = path.substring(0, path.lastIndexOf(DirectoryManager.FILESYSTEM_SEPARATOR) + 1);
3334
}
3435

3536
public String injectLessonVariables() {

‎koans-lib/src/com/sandwich/util/io/FileUtils.java‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,22 @@ public static String readFileAsString(File file) {
8282
}
8383

8484
public static String getContentsOfOriginalJavaFile(String className) {
85-
File sourceFile = new File( DirectoryManager.getSourceDir()
86-
+ DirectoryManager.FILESYSTEM_SEPARATOR
87-
+ classNameToJavaFileName(className));
88-
if(!sourceFile.exists()){
89-
throw new RuntimeException(new FileNotFoundException(sourceFile.getAbsolutePath()+" does not exist"));
90-
}
91-
return readFileAsString(sourceFile);
85+
return readFileAsString(getSourceFileFromClass(className));
9286
}
9387

94-
private static String classNameToJavaFileName(String className) {
88+
public static File getSourceFileFromClass(String className) {
89+
File sourceFile = new File(
90+
DirectoryManager.getSourceDir()
91+
+ DirectoryManager.FILESYSTEM_SEPARATOR
92+
+ classNameToJavaFileName(className));
93+
if (!sourceFile.exists()) {
94+
throw new IllegalArgumentException(new FileNotFoundException(
95+
sourceFile.getAbsolutePath() + " does not exist"));
96+
}
97+
return sourceFile;
98+
}
99+
100+
public static String classNameToJavaFileName(String className) {
95101
className = className.replace(KoanConstants.PERIOD, DirectoryManager.FILESYSTEM_SEPARATOR);
96102
if(className.contains(DOLLAR_SIGN)){
97103
className = className.substring(0, className.indexOf(DOLLAR_SIGN));

‎koans-tests/test/com/sandwich/koan/KoansResultTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
import org.junit.Test;
88

9+
import com.sandwich.koan.path.CommandLineTestCase;
910
import com.sandwich.koan.result.KoanMethodResult;
1011
import com.sandwich.koan.result.KoanSuiteResult;
1112
import com.sandwich.koan.result.KoanSuiteResult.KoanResultBuilder;
1213
import com.sandwich.koan.suite.OneFailingKoan;
1314

14-
public class KoansResultTest {
15-
15+
public class KoansResultTest extends CommandLineTestCase {
16+
1617
@Test
1718
public void testToString() throws Exception {
1819
KoanResultBuilder builder = new KoanResultBuilder()

‎koans-tests/test/com/sandwich/koan/path/RbVariableInjectorTest.java‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.sandwich.koan.path.xmltransformation.RbVariableInjector;
1111
import com.sandwich.koan.suite.OneFailingKoan;
1212

13-
public class RbVariableInjectorTest {
13+
public class RbVariableInjectorTest extends CommandLineTestCase {
1414

1515
@Test
1616
public void construction_nullMethod() throws Exception {
@@ -22,16 +22,6 @@ public void construction_nullMethod() throws Exception {
2222
}
2323
}
2424

25-
// @Test
26-
// public void construction_nullLesson() throws Exception {
27-
// try{
28-
// new XmlVariableInjector(null, Object.class.getDeclaredMethod("equals", Object.class));
29-
// fail("why construct w/ null lesson?");
30-
// }catch(IllegalArgumentException t){
31-
// // this is ok - we want this!
32-
// }
33-
// }
34-
3525
@Test
3626
public void injectInputVariables_filePath() throws Exception {
3727
String lesson = "meh ${file_path}";

‎koans-tests/test/com/sandwich/koan/runner/ui/AbstractSuitePresenterTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import org.junit.Test;
99

1010
import com.sandwich.koan.KoanMethod;
11+
import com.sandwich.koan.path.CommandLineTestCase;
1112
import com.sandwich.koan.result.KoanMethodResult;
1213
import com.sandwich.koan.result.KoanSuiteResult;
1314
import com.sandwich.koan.result.KoanSuiteResult.KoanResultBuilder;
1415
import com.sandwich.koan.suite.OneFailingKoan;
1516
import com.sandwich.koan.ui.AbstractSuitePresenter;
1617

17-
public class AbstractSuitePresenterTest {
18+
public class AbstractSuitePresenterTest extends CommandLineTestCase {
1819

1920
@Test
2021
public void testForwardingOneHundredPercentSuccess() throws Exception {

‎koans/lib/koans.jar‎

108 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)