Beispiel #1
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();
                                }
                            });
        }