From 029e12ad7b0102539466478005ed6a6656be94fd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 29 May 2011 12:30:19 -0400 Subject: [PATCH] can write out a reporting file --- Gemfile | 5 ++- Guardfile | 23 +++++++++++++ bin/jasmine-headless-webkit | 15 ++++++--- ext/jasmine-webkit-specrunner/specrunner.cpp | 34 +++++++++++++++++--- lib/jasmine/cli.rb | 13 ++++++++ spec/bin/jasmine-headless-webkit_spec.rb | 34 ++++++++++++++++++-- 6 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 Guardfile diff --git a/Gemfile b/Gemfile index 7799a83..26008d8 100644 --- a/Gemfile +++ b/Gemfile @@ -4,5 +4,8 @@ source "http://rubygems.org" gemspec gem 'rspec' -gem 'autotest' gem 'fakefs', :require => nil +gem 'guard' +gem 'guard-rspec' +gem 'guard-shell' +gem 'growl' diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..1b2b482 --- /dev/null +++ b/Guardfile @@ -0,0 +1,23 @@ + +# Add files and commands to this file, like the example: +# watch('file/path') { `command(s)` } +# + +guard 'shell' do + watch(%r{ext/jasmine-webkit-specrunner/specrunner.cpp}) { compile } +end +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb}) + watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^bin/(.+)}) { |m| "spec/bin/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } +end + +def compile + system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb} +end + +compile diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index d0d1a3b..61e23c4 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -2,7 +2,10 @@ require 'rubygems' -gem_dir = File.expand_path('../..', __FILE__) +def gem_dir + File.expand_path('../..', __FILE__) +end + $:.unshift(File.join(gem_dir, 'lib')) require 'yaml' @@ -25,13 +28,15 @@ opts = GetoptLong.new( [ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ], [ '--keep', GetoptLong::NO_ARGUMENT ], + [ '--report', GetoptLong::REQUIRED_ARGUMENT ], [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ] ) options = { :colors => false, :remove_html_file => true, - :jasmine_config => 'spec/javascripts/support/jasmine.yml' + :jasmine_config => 'spec/javascripts/support/jasmine.yml', + :report => false } @process_options = lambda { |*args| @@ -42,8 +47,10 @@ options = { options[:colors] = true when '--no-colors', '-nc' options[:colors] = false - when '--keep', '-k' + when '--keep' options[:remove_html_file] = false + when '--report' + options[:report] = arg when '--jasmine-config', '-j' options[:jasmine_config] = arg end @@ -97,7 +104,7 @@ files = files.collect { |file| output = jasmine_html_template(files) File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output } -system %{#{File.join(gem_dir, RUNNER)} #{options[:colors] ? '-c' : ''} #{target}} +system jasmine_command(options, target) status = $?.exitstatus FileUtils.rm_f target if options[:remove_html_file] || (status == 0) diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index 26523cc..1f68c2a 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -23,6 +23,8 @@ #include #include +#include +#include #include #if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) @@ -64,6 +66,7 @@ public: HeadlessSpecRunner(); void load(const QString &spec); void setColors(bool colors); + void reportFile(const QString &file); public slots: void log(const QString &msg); void specPassed(); @@ -88,6 +91,7 @@ private: bool isFinished; bool didFail; bool consoleNotUsedThisRun; + QString reportFilename; void red(); void green(); @@ -142,6 +146,11 @@ void HeadlessSpecRunner::setColors(bool colors) showColors = colors; } +void HeadlessSpecRunner::reportFile(const QString &file) +{ + reportFilename = file; +} + void HeadlessSpecRunner::red() { if (showColors) std::cout << "\033[0;31m"; @@ -246,6 +255,18 @@ void HeadlessSpecRunner::finishSuite(const QString &duration, const QString &tot clear(); std::cout << std::endl; + if (!reportFilename.isEmpty()) { + QFile reportFH(reportFilename); + + if (reportFH.open(QFile::WriteOnly)) { + QTextStream report(&reportFH); + report << qPrintable(total) << "/" << qPrintable(failed) << "/"; + report << (usedConsole ? "T" : "F"); + report << "/" << qPrintable(duration) << "\n"; + reportFH.close(); + } + } + isFinished = true; } @@ -284,16 +305,20 @@ void HeadlessSpecRunner::timerEvent(QTimerEvent *event) int main(int argc, char** argv) { - bool showColors = false; char *filename = NULL; + char *reporter = NULL; + char showColors = false; int c, index; - while ((c = getopt(argc, argv, "c")) != -1) { + while ((c = getopt(argc, argv, "cr:")) != -1) { switch(c) { case 'c': showColors = true; break; + case 'r': + reporter = optarg; + break; } } @@ -311,10 +336,11 @@ int main(int argc, char** argv) } QApplication app(argc, argv); - HeadlessSpecRunner runner; - runner.setColors(showColors); + runner.setColors(true); + runner.reportFile(reporter); runner.load(QString::fromLocal8Bit(filename)); return app.exec(); } + diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb index 5dedc53..73072da 100644 --- a/lib/jasmine/cli.rb +++ b/lib/jasmine/cli.rb @@ -52,6 +52,19 @@ module Jasmine HTML end + def runner_path + @runner_path ||= File.join(gem_dir, RUNNER) + end + + def jasmine_command(options, target) + [ + runner_path, + options[:colors] ? '-c' : nil, + options[:report] ? "-r #{options[:report]}" : nil, + target + ].join(" ") + end + private def read_config_file(file) diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb index 4d85601..b66ca83 100644 --- a/spec/bin/jasmine-headless-webkit_spec.rb +++ b/spec/bin/jasmine-headless-webkit_spec.rb @@ -1,24 +1,52 @@ require 'spec_helper' describe "jasmine-headless-webkit" do + let(:report) { 'spec/report.txt' } + + before do + FileUtils.rm_f report + end + + after do + FileUtils.rm_f report + end + describe 'success' do it "should succeed with error code 0" do - %x{bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml} + system %{bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --report #{report}} $?.exitstatus.should == 0 + + parts = File.read(report).strip.split('/') + parts.length.should == 4 + parts[0].should == "1" + parts[1].should == "0" + parts[2].should == "F" end end describe 'failure' do it "should fail with an error code of 1" do - %x{bin/jasmine-headless-webkit -j spec/jasmine/failure/failure.yml} + system %{bin/jasmine-headless-webkit -j spec/jasmine/failure/failure.yml --report #{report}} $?.exitstatus.should == 1 + + parts = File.read(report).strip.split('/') + parts.length.should == 4 + parts[0].should == "1" + parts[1].should == "1" + parts[2].should == "F" end end describe 'with console.log' do it "should succeed, but has a console.log so an error code of 2" do - %x{bin/jasmine-headless-webkit -j spec/jasmine/console_log/console_log.yml} + system %{bin/jasmine-headless-webkit -j spec/jasmine/console_log/console_log.yml --report #{report}} $?.exitstatus.should == 2 + + parts = File.read(report).strip.split('/') + parts.length.should == 4 + parts[0].should == "1" + parts[1].should == "0" + parts[2].should == "T" end end end