Exemplo n.º 1
0
        public void VersionHeaderSpecifications()
        {
            Runner runner = null;
            "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser()));

            "version and copyright information is written to console"
                .Assert(() =>
                            {
                                var version = Assembly.GetAssembly(typeof (Parser)).GetName().Version;
                                var expectedText = string.Format("\r\nRivet JavaScript Combiner v{0}.{1}\r\nCopyright © 2010, Dave Taylor and Arnold Zokas\r\n", version.Major, version.Minor);

                                using (var session = new ConsoleSession())
                                {
                                    runner.Execute(new string[0]);
                                    session.StandardOutput.ShouldContain(expectedText);
                                }
                            });
        }
Exemplo n.º 2
0
        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);
                                    }
                                }
                            });
        }
Exemplo n.º 3
0
        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));
                                    }
                                }
                            });
        }
Exemplo n.º 4
0
        public void MissingDirectoryParameterParsingSpecifications()
        {
            Runner runner = null;
            "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser()));

            "when Execute is invoked with parameter \"X:\\not_a_real_directory\", message \"Directory X:\\not_a_real_directory could not be found.\" is written to console"
                .Assert(() =>
                            {
                                using (var session = new ConsoleSession())
                                {
                                    runner.Execute("X:\\not_a_real_directory");
                                    session.StandardError.ShouldContain("Directory \"X:\\not_a_real_directory\" could not be found.");
                                }
                            });
        }
Exemplo n.º 5
0
        public void HelpSpecifications()
        {
            Runner runner = null;
            var expectedOutput = string.Format(
                "{0}Usage: Rivet.Console.exe [/help] <path> [options]{0}{0}" +
                "\t/help\tShows this help information{0}" +
                "\t<path>\tPath to directory containing javascript files{0}{0}" +
                "Options:{0}" +
                "\t-v:name=value\tReplaces token [name] with [value] in processed files.{0}" +
                "\t\t\tThis can be specified multiple times to replace{0}" +
                "\t\t\tmultiple tokens.{0}{0}" +
                "Example:{0}{0}" +
                "\tRivet.Console.exe D:\\website\\js -v:debug=false -v:trace=true{0}"
                , Environment.NewLine);

            "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser()));

            var parameters = new string[0];
            "when Execute is invoked with no parameters".Do(() => runner.Execute(parameters));

            "DisplayHelpInformation parameter is set to true".Assert(() => runner.Parameters.DisplayHelpInformation.ShouldBeTrue());
            "help information is written to console"
                .Assert(() =>
                            {
                                using (var session = new ConsoleSession())
                                {
                                    runner.Execute(parameters);
                                    session.StandardOutput.ShouldContain(expectedOutput);
                                }
                            });
        }
Exemplo n.º 6
0
        public void EmptyDirectoryParameterParsingSpecifications()
        {
            Runner runner = null;
            "Given new Runner".Context(() => runner = new Runner(new ConsoleLogWriter(), new ConsoleParameterParser()));

            "when Execute is invoked with parameter pointing to an empty directory, message \"Directory <path-to-dir> does not contain any javascript files.\" is written to console"
                .Assert(() =>
                            {
                                using (var session = new ConsoleSession())
                                {
                                    using (var tempDirectory = new TempDirectory())
                                    {
                                        runner.Execute(tempDirectory.Path);
                                        session.StandardError.ShouldContain(string.Format("Directory \"{0}\" does not contain any javascript files.", tempDirectory.Path));
                                    }
                                }
                            });
        }