diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 6eab319..39941d8 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -18,6 +18,7 @@ Runner::Runner() : QObject() , usedConsole(false) , isFinished(false) , useColors(false) + , quiet(false) { page.settings()->enablePersistentStorage(); ticker.setInterval(TIMER_TICK); @@ -122,10 +123,18 @@ void Runner::setSeed(QString s) { seed = s; } +void Runner::setQuiet(bool q) { + quiet = q; +} + QString Runner::getSeed() { return seed; } +bool Runner::isQuiet() { + return quiet; +} + void Runner::print(const QString &fh, const QString &content) { if (fh == "stdout") { std::cout << qPrintable(content); diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 8b65a46..8d7269e 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -22,6 +22,7 @@ class Runner: public QObject { void setColors(bool colors); void setReportFiles(QStack &files); void setSeed(QString s); + void setQuiet(bool q); void addFile(const QString &spec); void go(); @@ -33,6 +34,7 @@ class Runner: public QObject { void hasError(); void hasSpecFailure(); + bool isQuiet(); QString getSeed(); void print(const QString &fh, const QString &content); @@ -54,6 +56,7 @@ class Runner: public QObject { bool usedConsole; bool isFinished; bool useColors; + bool quiet; QString seed; diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index 22d94ac..9f961d7 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -30,17 +30,20 @@ int main(int argc, char** argv) { bool showColors = false; + bool isQuiet = false; QString seed; - QStack reporterFiles; int c, index; - while ((c = getopt(argc, argv, "cr:s:")) != -1) { + while ((c = getopt(argc, argv, "cr:s:q")) != -1) { switch(c) { case 'c': showColors = true; break; + case 'q': + isQuiet = true; + break; case 'r': reporterFiles.push(QString(optarg)); break; @@ -61,6 +64,7 @@ int main(int argc, char** argv) Runner runner; runner.setColors(showColors); + runner.setQuiet(isQuiet); runner.setReportFiles(reporterFiles); runner.setSeed(seed); diff --git a/features/bin/quiet_messages.feature b/features/bin/quiet_messages.feature new file mode 100644 index 0000000..36be433 --- /dev/null +++ b/features/bin/quiet_messages.feature @@ -0,0 +1,8 @@ +Feature: Bin - Quiet Messages + Scenario: Run a test that would cause a lot of messages to be displayed and silence them all + Given I have a test suite + When I run `bin/jasmine-headless-webkit -q -j spec/jasmine/noisy/noisy.yml` + Then the exit status should be 0 + And the output should not include "[Skipping File]" + And the output should not include "You should mock" + diff --git a/features/steps/then/bin/output_should_not_include.rb b/features/steps/then/bin/output_should_not_include.rb new file mode 100644 index 0000000..e4a1716 --- /dev/null +++ b/features/steps/then/bin/output_should_not_include.rb @@ -0,0 +1,4 @@ +Then /^the output should not include "([^"]*)"$/ do |string| + @output.should_not include(string) +end + diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index a1dae0b..0a60efa 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -35,6 +35,24 @@ module Jasmine def root @root ||= Pathname(File.expand_path('../../..', __FILE__)) end + + def warn(message) + output.puts message if show_warnings? + end + + def show_warnings=(show) + @show_warnings = show + end + + def show_warnings? + @show_warnings = true if @show_warnings.nil? + + @show_warnings + end + + def output + $stdout + end end end end diff --git a/lib/jasmine/headless/file_checker.rb b/lib/jasmine/headless/file_checker.rb index fd7a3a7..6795a5b 100644 --- a/lib/jasmine/headless/file_checker.rb +++ b/lib/jasmine/headless/file_checker.rb @@ -1,14 +1,18 @@ module Jasmine::Headless::FileChecker + def excluded_formats + ::Jasmine::Headless::EXCLUDED_FORMATS + end + def bad_format?(file) return if file.nil? - ::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format| + excluded_formats.any? do |format| file[%r{\.#{format}(\.|$)}] end end - + def alert_bad_format(file) - puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ] + Jasmine::Headless.warn("[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ]) end def alert_if_bad_format?(file) diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index 8a51cf8..49e8202 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -17,9 +17,8 @@ module Jasmine :full_run => true, :enable_cache => true, :files => [], - :reporters => [ - [ 'Console' ] - ] + :reporters => [ [ 'Console' ] ], + :quiet => false } DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') @@ -39,6 +38,7 @@ module Jasmine srand @options[:seed] = rand(10000) read_defaults_files + opts.each { |k, v| @options[k] = v if v } end @@ -69,6 +69,8 @@ module Jasmine @options[:full_run] = false when '--list', '-l' @options[:do_list] = true + when '--quiet', '-q' + @options[:quiet] = true when '--seed' @options[:seed] = arg.to_i when '--format', '-f' @@ -105,7 +107,8 @@ module Jasmine [ '--seed', GetoptLong::REQUIRED_ARGUMENT ], [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ], [ '--out', GetoptLong::REQUIRED_ARGUMENT ], - [ '-h', '--help', GetoptLong::NO_ARGUMENT ] + [ '-h', '--help', GetoptLong::NO_ARGUMENT ], + [ '-q', '--quiet', GetoptLong::NO_ARGUMENT ] ) command_line_args.each { |*args| process_option(*args) } @@ -166,6 +169,7 @@ module Jasmine [ '--seed', 'Random order seed for spec file ordering' ], [ '-f, --format >', 'Specify an output reporter and possibly output filename' ], [ '--out ', 'Specify output filename for last defined reporter' ], + [ '-q, --quiet', "Silence most non-test related warnings" ], [ '-h, --help', "You're looking at it" ] ] @@ -179,6 +183,7 @@ Options: Available reporters: Console Write out spec results to the console in a progress format (default) + Verbose Write out spec results to the console in a verbose format File Write spec results in jasmine-headless-webkit ReportFile format Tap Write spec results in TAP format diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 110cf6e..fdb4b5f 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -57,6 +57,7 @@ module Jasmine command << "-s #{options[:seed]}" command << '-c' if options[:colors] + command << '-q' if options[:quiet] options.file_reporters.each do |reporter, identifier, file| command << "-r #{file}" @@ -69,6 +70,7 @@ module Jasmine def run Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache] + Jasmine::Headless.show_warnings = !@options[:quiet] FilesList.reset! @_targets = template_writer.write diff --git a/spec/jasmine/noisy/file.js.erb b/spec/jasmine/noisy/file.js.erb new file mode 100644 index 0000000..e69de29 diff --git a/spec/jasmine/noisy/noisy.yml b/spec/jasmine/noisy/noisy.yml new file mode 100644 index 0000000..c001d27 --- /dev/null +++ b/spec/jasmine/noisy/noisy.yml @@ -0,0 +1,8 @@ +src_dir: spec/jasmine/noisy +src_files: +- '**/*' + +spec_dir: spec/jasmine/noisy +spec_files: +- '**/*' + diff --git a/spec/jasmine/noisy/other_file.js b/spec/jasmine/noisy/other_file.js new file mode 100644 index 0000000..213323b --- /dev/null +++ b/spec/jasmine/noisy/other_file.js @@ -0,0 +1,2 @@ +window.prompt("hello"); + diff --git a/spec/lib/jasmine/headless/file_checker_spec.rb b/spec/lib/jasmine/headless/file_checker_spec.rb index 0e14a11..d105222 100644 --- a/spec/lib/jasmine/headless/file_checker_spec.rb +++ b/spec/lib/jasmine/headless/file_checker_spec.rb @@ -1,25 +1,41 @@ require 'spec_helper' describe Jasmine::Headless::FileChecker do - include FakeFS::SpecHelpers - let(:test_class) do object = Object.new object.class.send(:include, Jasmine::Headless::FileChecker) object end - context "bad_format?" do - it "should return false wth correct format" do - test_class.bad_format?('foobar.js').should be_false + describe "#bad_format?" do + subject { test_class.bad_format?(file) } + + before do + test_class.stubs(:excluded_formats).returns(%w{erb string}) end - it "should return false wth wrong format" do - test_class.bad_format?('foobar.js.erb').should be_true + context 'nil' do + let(:file) { nil } + + it { should be_nil } end - it "should check for the whole extension" do - test_class.bad_format?('foobar.string.js').should be_false + context 'allowed format' do + let(:file) { 'foobar.js' } + + it { should be_false } + end + + context 'unallowed format' do + let(:file) { 'foobar.erb' } + + it { should be_true } + end + + context 'check whole extension' do + let(:file) { 'foobar.string.js' } + + it { should be_true } end end end diff --git a/spec/lib/jasmine/headless/runner_spec.rb b/spec/lib/jasmine/headless/runner_spec.rb index 3b86c22..dcd4650 100644 --- a/spec/lib/jasmine/headless/runner_spec.rb +++ b/spec/lib/jasmine/headless/runner_spec.rb @@ -91,6 +91,15 @@ describe Jasmine::Headless::Runner do it_should_have_basics it { should include("-r #{file}") } end + + context 'quiet' do + before do + options[:quiet] = true + end + + it_should_have_basics + it { should include("-q") } + end end describe '#runner_filename' do diff --git a/spec/lib/jasmine/headless_spec.rb b/spec/lib/jasmine/headless_spec.rb index 51f5efc..ca15d2f 100644 --- a/spec/lib/jasmine/headless_spec.rb +++ b/spec/lib/jasmine/headless_spec.rb @@ -1,2 +1,38 @@ require 'spec_helper' +describe Jasmine::Headless do + describe '.warn' do + let(:output) { StringIO.new } + + before do + described_class.stubs(:output).returns(output) + end + + context 'warnings enabled' do + before do + described_class.stubs(:show_warnings?).returns(true) + end + + it 'should work' do + described_class.warn("warning") + + output.rewind + output.read.should == "warning\n" + end + end + + context 'warnings disabled' do + before do + described_class.stubs(:show_warnings?).returns(false) + end + + it 'should work' do + described_class.warn("warning") + + output.rewind + output.read.should == "" + end + end + end +end + diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index 3ca660e..d999175 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -29,12 +29,15 @@ if window.JHW puts = (message) -> JHW.print('stdout', message + "\n") + warn = (message) -> + puts(message) if !JHW.isQuiet() + # handle unloading window.onbeforeunload = (e) -> e = e || window.event JHW.hasError() - puts "The code tried to leave the test page. Check for unhandled form submits and link clicks." + warn "The code tried to leave the test page. Check for unhandled form submits and link clicks." e.returnValue = 'string' if e @@ -49,17 +52,17 @@ if window.JHW # dialogs window.confirm = -> - puts "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true." + warn "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true." true window.prompt = -> - puts "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true." + warn "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true." true window.alert = (message) -> - puts "[alert] ".foreground('red') + message + warn "[alert] ".foreground('red') + message # color support JHW._setColors = (useColors) -> Intense.useColors = useColors diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index 72a490f..6ccdbc5 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -1,5 +1,6 @@ (function() { - var puts; + var puts, warn; + if (window.JHW) { window.console = { log: function(data) { @@ -39,13 +40,14 @@ puts = function(message) { return JHW.print('stdout', message + "\n"); }; + warn = function(message) { + if (!JHW.isQuiet()) return puts(message); + }; window.onbeforeunload = function(e) { e = e || window.event; JHW.hasError(); - puts("The code tried to leave the test page. Check for unhandled form submits and link clicks."); - if (e) { - e.returnValue = 'string'; - } + warn("The code tried to leave the test page. Check for unhandled form submits and link clicks."); + if (e) e.returnValue = 'string'; return 'string'; }; JHW._hasErrors = false; @@ -55,15 +57,15 @@ return false; }; window.confirm = function() { - puts("" + ("[confirm]".foreground('red')) + " You should mock window.confirm. Returning true."); + warn("" + ("[confirm]".foreground('red')) + " You should mock window.confirm. Returning true."); return true; }; window.prompt = function() { - puts("" + ("[prompt]".foreground('red')) + " You should mock window.prompt. Returning true."); + warn("" + ("[prompt]".foreground('red')) + " You should mock window.prompt. Returning true."); return true; }; window.alert = function(message) { - return puts("[alert] ".foreground('red') + message); + return warn("[alert] ".foreground('red') + message); }; JHW._setColors = function(useColors) { return Intense.useColors = useColors; @@ -75,14 +77,15 @@ _ref = jasmine.getEnv().reporter.subReporters_; for (_i = 0, _len = _ref.length; _i < _len; _i++) { reporter = _ref[_i]; - if (reporter.consoleLogUsed != null) { - reporter.consoleLogUsed(msg); - } + if (reporter.consoleLogUsed != null) reporter.consoleLogUsed(msg); } JHW._usedConsole = true; return puts(msg); }; } + window.CoffeeScriptToFilename = {}; + window.CSTF = window.CoffeeScriptToFilename; + }).call(this);