can write out a reporting file

This commit is contained in:
John Bintz 2011-05-29 12:30:19 -04:00
parent 1be31e800e
commit 029e12ad7b
6 changed files with 112 additions and 12 deletions

View File

@ -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'

23
Guardfile Normal file
View File

@ -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

View File

@ -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)

View File

@ -23,6 +23,8 @@
#include <QtGui>
#include <QtWebKit>
#include <QFile>
#include <QTextStream>
#include <iostream>
#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();
}

View File

@ -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)

View File

@ -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