public void MainSpecifications() { "Given Program".Context(); "when Main is invoked with no parameters, DisplayHelpInformation parameter is set to true" .Assert(() => { Program.Main(new string[0]); Program.Parameters.DisplayHelpInformation.ShouldBeTrue(); }); "Main returns 1 when invoked with no parameters".Assert(() => Program.Main(new string[0]).ShouldEqual(1)); "Main returns 0 when invoked with parameter \"<path-to-dir>\"" .Assert(() => { using (var tempDirectory = new TempDirectory()) { /* create filesystem strucure: * %TEMP%\main.js * %TEMP%\include.js */ tempDirectory.CreateFile("main.js", @"@rivet includes.push(""include.js"");"); tempDirectory.CreateFile("include.js", @"A"); Program.Main(new[] {tempDirectory.Path}).ShouldEqual(0); } }); }
public void CombiningSpecifications() { Rivet task = null; "Given new Rivet task".Context(() => task = new Rivet {BuildEngine = new FakeBuildEngine()}); "Execute returns false when invoked with invalid parameters".Assert(() => task.Execute().ShouldBeFalse()); "when Execute is invoked with parameters \"<path-to-dir> -v:debug=false -v:trace=true\", javascript files in the target directory are combined" .Assert(() => { using (var tempDirectory = new TempDirectory()) { /* create filesystem strucure: * %TEMP%\main.js * %TEMP%\secondary.js * %TEMP%\dirWithComponentFile\include.js * %TEMP%\dirWithStandaloneFile\standalone.js * %TEMP%\dirWithNestedComponentFiles\include.js * %TEMP%\dirWithNestedComponentFiles\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\standalone.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\subdir\standalone.js */ tempDirectory.CreateFile("main.js", @"@rivet includes.push(""dirWithComponentFile/include.js""); includes.push(""dirWithNestedComponentFiles/include.js""); includes.push(""dirWithNestedComponentFiles/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/subdir/include.js""); "); tempDirectory.CreateFile("secondary.js", @"@rivet includes.push(""dirWithNestedComponentFiles/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/include.js""); "); tempDirectory.CreateDirectory("dirWithComponentFile"); tempDirectory.CreateFile("dirWithComponentFile\\include.js", "BEFORE\r\n//##DEBUG_STARTTEST\r\n//##DEBUG_ENDAFTER\r\n"); tempDirectory.CreateDirectory("dirWithStandaloneFile"); tempDirectory.CreateFile("dirWithStandaloneFile\\standalone.js", "standalone js file"); tempDirectory.CreateDirectory("dirWithNestedComponentFiles"); tempDirectory.CreateFile("dirWithNestedComponentFiles\\include.js", "BEFORE_LINE\r\nTHIS_SHOULD_BE_REMOVED;//##DEBUGAFTER_LINE\r\n"); tempDirectory.CreateDirectory("dirWithNestedComponentFiles\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFiles\\subdir\\include.js", "A"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\include.js", "B"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\standalone.js", "standalone js file"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\subdir\\include.js", "C"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile2"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\include.js", "D"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile2\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\subdir\\include.js", "var i = @VARIABLE_1;var j = @VARIABLE_2;"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\subdir\\standalone.js", "standalone js file"); task.TargetDirectory = tempDirectory.Path; task.Variables = "VARIABLE_1=false;VARIABLE_2=true"; task.Execute().ShouldBeTrue(); tempDirectory.ReadFile("main.js").ShouldEqual("BEFORE\r\nAFTER\r\nBEFORE_LINEAFTER_LINE\r\nABCDvar i = false;var j = true;"); tempDirectory.ReadFile("secondary.js").ShouldEqual("ABCD"); tempDirectory.DirectoryExists("dirWithComponentFile").ShouldBeFalse(); tempDirectory.FileExists("dirWithStandaloneFile\\standalone.js").ShouldBeTrue(); tempDirectory.DirectoryExists("dirWithNestedComponentFiles").ShouldBeFalse(); tempDirectory.FileExists("dirWithNestedComponentFilesAndStandaloneFile\\standalone.js").ShouldBeTrue(); tempDirectory.DirectoryExists("dirWithNestedComponentFilesAndStandaloneFile\\subdir").ShouldBeFalse(); tempDirectory.DirectoryExists("dirWithNestedComponentFilesAndStandaloneFile2\\subdir").ShouldBeTrue(); } }); }
public void CombiningSpecifications() { // NOTE: this is a good candidate for refactoring. I need to implement some sort of API in xUnit.Specifications to simplify filesystem testing Runner runner = null; "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser())); "when Execute is invoked with parameters \"<path-to-dir> -v:debug=false -v:trace=true\", javascript files in the target directory are combined" .Assert(() => { using (var tempDirectory = new TempDirectory()) { /* create filesystem strucure: * %TEMP%\main.js * %TEMP%\secondary.js * %TEMP%\dirWithComponentFile\include.js * %TEMP%\dirWithStandaloneFile\standalone.js * %TEMP%\dirWithNestedComponentFiles\include.js * %TEMP%\dirWithNestedComponentFiles\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\standalone.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\subdir\include.js * %TEMP%\dirWithNestedComponentFilesAndStandaloneFile2\subdir\standalone.js * %TEMP%\dir\rivet.js * %TEMP%\dir\lib\include.js */ tempDirectory.CreateFile("main.js", @"@rivet includes.push(""dirWithComponentFile/include.js""); includes.push(""dirWithNestedComponentFiles/include.js""); includes.push(""dirWithNestedComponentFiles/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/subdir/include.js""); "); tempDirectory.CreateFile("secondary.js", @"@rivet includes.push(""dirWithNestedComponentFiles/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile/subdir/include.js""); includes.push(""dirWithNestedComponentFilesAndStandaloneFile2/include.js""); "); tempDirectory.CreateDirectory("dirWithComponentFILE"); tempDirectory.CreateFile("dirWithComponentFile\\INCLUDE.js", "BEFORE\r\n//##DEBUG_STARTTEST\r\n//##DEBUG_ENDAFTER\r\n"); tempDirectory.CreateDirectory("dirWithStandaloneFile"); tempDirectory.CreateFile("dirWithStandaloneFile\\standalone.js", "standalone js file"); tempDirectory.CreateDirectory("dirWithNestedComponentFiles"); tempDirectory.CreateFile("dirWithNestedComponentFiles\\include.js", "BEFORE_LINE\r\nTHIS_SHOULD_BE_REMOVED;//##DEBUGAFTER_LINE\r\n"); tempDirectory.CreateDirectory("dirWithNestedComponentFiles\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFiles\\subdir\\include.js", "A"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\include.js", "B"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\standalone.js", "standalone js file"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile\\subdir\\include.js", "C"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile2"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\include.js", "D"); tempDirectory.CreateDirectory("dirWithNestedComponentFilesAndStandaloneFile2\\subdir"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\subdir\\include.js", "var i = @VARIABLE_1;var j = @VARIABLE_2;"); tempDirectory.CreateFile("dirWithNestedComponentFilesAndStandaloneFile2\\subdir\\standalone.js", "standalone js file"); tempDirectory.CreateDirectory("dir"); tempDirectory.CreateFile("dir\\rivet.js", @"@rivet includes.push(""lib/include.js"");"); tempDirectory.CreateDirectory("dir\\lib"); tempDirectory.CreateFile("dir\\lib\\include.js", @"TEST"); runner.Execute(new[] {tempDirectory.Path, " -v:VARIABLE_1=false", "-v:VARIABLE_2=true"}).ShouldBeTrue(); tempDirectory.ReadFile("main.js").ShouldEqual("BEFORE\r\nAFTER\r\nBEFORE_LINEAFTER_LINE\r\nABCDvar i = false;var j = true;"); tempDirectory.ReadFile("secondary.js").ShouldEqual("ABCD"); tempDirectory.ReadFile("dir\\rivet.js").ShouldEqual("TEST"); tempDirectory.DirectoryExists("dirWithComponentFile").ShouldBeFalse(); tempDirectory.FileExists("dirWithStandaloneFile\\standalone.js").ShouldBeTrue(); tempDirectory.DirectoryExists("dirWithNestedComponentFiles").ShouldBeFalse(); tempDirectory.FileExists("dirWithNestedComponentFilesAndStandaloneFile\\standalone.js").ShouldBeTrue(); tempDirectory.DirectoryExists("dirWithNestedComponentFilesAndStandaloneFile\\subdir").ShouldBeFalse(); tempDirectory.DirectoryExists("dirWithNestedComponentFilesAndStandaloneFile2\\subdir").ShouldBeTrue(); } }); }
public void RuntimeInfoSpecifications() { Runner runner = null; "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser())); "when Execute is invoked, TargetDirectory path is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet"); runner.Execute(tempDirectory.Path); var expectedText = string.Format("\r\nTarget directory: {0}\r\n", tempDirectory.Path); session.StandardOutput.ShouldContain(expectedText); } } }); "when Execute is invoked, list of discovered source files is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet"); tempDirectory.CreateDirectory("dir"); tempDirectory.CreateFile("dir\\include.js", "TEST"); runner.Execute(tempDirectory.Path); const string expectedText = "Discovered 2 javascript file(s):\r\n\t- main.js\r\n\t- dir\\include.js\r\n"; session.StandardOutput.ShouldContain(expectedText); } } }); "when Execute is invoked, list of parser options is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet"); runner.Execute(tempDirectory.Path, "-v:debug=false", "-v:trace=true"); const string expectedText = "Variables:\r\n\t- debug=false\r\n\t- trace=true"; session.StandardOutput.ShouldContain(expectedText); } } }); "when Execute is invoked, path of Rivet output file is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet"); runner.Execute(tempDirectory.Path); var expectedText = string.Format("\r\nSaved combined file: {0}\r\n", Path.Combine(tempDirectory.Path, "main.js")); session.StandardOutput.ShouldContain(expectedText); } } }); "when Execute is invoked, list of deleted files is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet includes.push(\"dir/include.js\");"); tempDirectory.CreateDirectory("dir"); tempDirectory.CreateFile("dir\\include.js", "TEST"); runner.Execute(tempDirectory.Path); var expectedText = string.Format("\r\nDeleting components:\r\n\t- dir\\include.js"); session.StandardOutput.ShouldContain(expectedText); } } }); "when Execute is invoked, list of deleted directories is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", "@rivet"); tempDirectory.CreateDirectory("dir"); tempDirectory.CreateDirectory("dir2"); runner.Execute(tempDirectory.Path); var expectedText = string.Format("\r\nDeleted empty subdirectory \"{0}\\dir\"\r\n\r\nDeleted empty subdirectory \"{0}\\dir2\"\r\n", tempDirectory.Path); session.StandardOutput.ShouldContain(expectedText); } } }); }
public void RelativePathCombiningSpecifications() { Runner runner = null; "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser())); "when Execute is invoked with parameters with relative paths, file are combined correctly" .Assert(() => { using (var tempDirectory = new TempDirectory()) { /* create filesystem strucure: * %TEMP%\subdir\main.js * %TEMP%\include.js */ tempDirectory.CreateDirectory("subdir"); tempDirectory.CreateFile("subdir\\main.js", @"@rivet includes.push(""../include.js""); "); tempDirectory.CreateFile("include.js", "TEST"); runner.Execute(new[] {tempDirectory.Path}).ShouldBeTrue(); tempDirectory.ReadFile("subdir\\main.js").ShouldEqual("TEST"); } }); }
public void MissingFileReferenceParsingSpecifications() { Runner runner = null; "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser())); "when Execute is invoked with with source file that is referencing a file that does not exist, message \"Unable to combine. Source file \"<path-to-missing-file>\" referenced by \"<path-to-parent-file>\" could not be found.\" is written to console" .Assert(() => { using (var session = new ConsoleSession()) { using (var tempDirectory = new TempDirectory()) { tempDirectory.CreateFile("main.js", @"@rivet includes.push(""include.js"");"); runner.Execute(tempDirectory.Path); session.StandardError.ShouldContain(string.Format("Unable to combine. Source file \"include.js\" referenced by \"{0}\\main.js\" could not be found.", tempDirectory.Path)); } } }); }