Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
a whole ton of reporters work
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbintz committed Dec 29, 2011
1 parent 09f4df9 commit 0adf3a4
Show file tree
Hide file tree
Showing 61 changed files with 687 additions and 298 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Expand Up @@ -6,15 +6,20 @@ gemspec
gem 'rspec'
gem 'fakefs', :require => nil
gem 'guard'

gem 'guard-rspec'
gem 'guard-shell'
gem 'guard-coffeescript'
gem 'guard-cucumber'

gem 'growl'
gem 'rake', '0.8.7'
gem 'mocha', '0.9.12'
gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git'
gem 'facter'

gem 'cucumber'

gem 'jquery-rails'
gem 'ejs'

Expand Down
7 changes: 6 additions & 1 deletion Guardfile
Expand Up @@ -22,13 +22,18 @@ guard 'rspec', :version => 2, :all_on_start => false do
watch('spec/spec_helper.rb') { "spec" }
end

guard 'cucumber', :cli => '-r features --format pretty' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/steps/(.+)_steps\.rb$}) { 'features' }
end

guard 'jasmine-headless-webkit', :all_on_start => false do
watch(%r{^spec/javascripts/.+_spec\.coffee})
watch(%r{^jasmine/(.+)\.coffee$}) { |m| "spec/javascripts/#{m[1]}_spec.coffee" }
end

def compile
#system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb}
system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
end

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -30,6 +30,7 @@ namespace :spec do
task :platforms do
rvm_bundle
rvm_bundle "exec rspec spec"
rvm_bundle "exec cucumber"
raise SpecError.new if $?.exitstatus != 0
end
end
Expand Down
36 changes: 21 additions & 15 deletions ext/jasmine-webkit-specrunner/Runner.cpp
Expand Up @@ -62,8 +62,10 @@ void Runner::handleError(const QString &message, int lineNumber, const QString &

void Runner::loadSpec()
{
if (!reportFileName.isEmpty()) {
QFile *outputFile = new QFile(reportFileName);
QVectorIterator<QString> iterator(reportFiles);

while (iterator.hasNext()) {
QFile *outputFile = new QFile(iterator.next());
outputFile->open(QIODevice::WriteOnly);
outputFiles.enqueue(outputFile);
}
Expand Down Expand Up @@ -100,8 +102,8 @@ void Runner::hasSpecFailure() {
_hasSpecFailure = true;
}

void Runner::reportFile(const QString &file) {
reportFileName = file;
void Runner::setReportFiles(QStack<QString> &files) {
reportFiles = files;
}

void Runner::timerPause() {
Expand All @@ -116,6 +118,14 @@ void Runner::ping() {
runs = 0;
}

void Runner::setSeed(QString s) {
seed = s;
}

QString Runner::getSeed() {
return seed;
}

void Runner::print(const QString &fh, const QString &content) {
if (fh == "stdout") {
std::cout << qPrintable(content);
Expand All @@ -127,14 +137,12 @@ void Runner::print(const QString &fh, const QString &content) {
std::cerr.flush();
}

if (fh == "report") {
QListIterator<QFile *> iterator(outputFiles);
if (fh.contains("report")) {
int index = (int)fh.split(":").last().toUInt();

while (iterator.hasNext()) {
QTextStream ts(iterator.next());
ts << qPrintable(content);
ts.flush();
}
QTextStream ts(outputFiles.at(index));
ts << qPrintable(content);
ts.flush();
}
}

Expand All @@ -150,10 +158,8 @@ void Runner::timerEvent() {
QApplication::instance()->exit(1);

if (isFinished && runs > 2) {
QListIterator<QFile *> iterator(outputFiles);

while (iterator.hasNext()) {
iterator.next()->close();
while (!outputFiles.isEmpty()) {
outputFiles.dequeue()->close();
}

int exitCode = 0;
Expand Down
14 changes: 9 additions & 5 deletions ext/jasmine-webkit-specrunner/Runner.h
Expand Up @@ -20,7 +20,9 @@ class Runner: public QObject {

Runner();
void setColors(bool colors);
void reportFile(const QString &file);
void setReportFiles(QStack<QString> &files);
void setSeed(QString s);

void addFile(const QString &spec);
void go();

Expand All @@ -30,6 +32,9 @@ class Runner: public QObject {
void hasUsedConsole();
void hasError();
void hasSpecFailure();

QString getSeed();

void print(const QString &fh, const QString &content);
void finishSuite();
void ping();
Expand All @@ -50,15 +55,14 @@ class Runner: public QObject {
bool isFinished;
bool useColors;

QQueue<QString> runnerFiles;
QString seed;

QString reportFileName;
QQueue<QString> runnerFiles;
QStack<QString> reportFiles;

void loadSpec();

QQueue<QFile *> outputFiles;

QFile *outputFile;
};

#endif
20 changes: 13 additions & 7 deletions ext/jasmine-webkit-specrunner/specrunner.cpp
Expand Up @@ -29,34 +29,40 @@

int main(int argc, char** argv)
{
char *reporter = NULL;
char showColors = false;
bool showColors = false;
QString seed;

QStack<QString> reporterFiles;

int c, index;

while ((c = getopt(argc, argv, "cr:")) != -1) {
while ((c = getopt(argc, argv, "cr:s:")) != -1) {
switch(c) {
case 'c':
showColors = true;
break;
case 'r':
reporter = optarg;
reporterFiles.push(QString(optarg));
break;
case 's':
seed = QString(optarg);
break;
}
}

if (optind == argc) {
std::cerr << "Run Jasmine's SpecRunner headlessly" << std::endl << std::endl;
std::cerr << " specrunner [-c] [-r <report file>] specrunner.html ..." << std::endl;
std::cerr << " specrunner [-c] [-s seed] [-r report file ...] specrunner.html ..." << std::endl;
return 1;
}

QApplication app(argc, argv);
app.setApplicationName("jasmine-headless-webkit");
Runner runner;
runner.setColors(showColors);

runner.reportFile(reporter);
runner.setColors(showColors);
runner.setReportFiles(reporterFiles);
runner.setSeed(seed);

for (index = optind; index < argc; index++) {
runner.addFile(QString::fromLocal8Bit(argv[index]));
Expand Down
7 changes: 7 additions & 0 deletions features/bin/failure.feature
@@ -0,0 +1,7 @@
Feature: Bin - Failure
Scenario: Run a failing test
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/failure/failure.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 1
And the report file "spec/report.txt" should have 1 total, 1 failure, no console usage

18 changes: 18 additions & 0 deletions features/bin/filtered_run/both_runs.feature
@@ -0,0 +1,18 @@
Feature: Bin - Filtered Run - Both Runs
Background:
Given there is no existing "spec/report.txt" file

Scenario: Run one and fail
When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_failure/filtered_failure.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_failure/failure_spec.js`
Then the exit status should be 1
And the report file "spec/report.txt" should have 1 total, 1 failure, no console usage

Scenario: Run both and succeed
When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success/success_one_spec.js`
Then the exit status should be 0
And the report file "spec/report.txt" should have 2 total, 0 failures, no console usage

Scenario: Run both with console.log
When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success_with_console/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success_with_console/success_one_spec.js`
Then the exit status should be 2
And the report file "spec/report.txt" should have 2 total, 0 failures, yes console usage
14 changes: 14 additions & 0 deletions features/bin/filtered_run/no_full_run.feature
@@ -0,0 +1,14 @@
Feature: Bin - No Full Run
Background:
Given there is no existing "spec/report.txt" file

Scenario: Only run the filtered run
When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt --no-full-run ./spec/jasmine/filtered_success/success_one_spec.js`
Then the exit status should be 0
And the report file "spec/report.txt" should have 1 total, 0 failure, no console usage

Scenario: Use a file outside of the normal test run
When I run `bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --format HeadlessFileReporter --out spec/report.txt ./spec/jasmine/filtered_success/success_other_file.js`
Then the exit status should be 0
And the report file "spec/report.txt" should have 1 total, 0 failure, no console usage

Empty file added features/bin/reporters.feature
Empty file.
20 changes: 20 additions & 0 deletions features/bin/success.feature
@@ -0,0 +1,20 @@
Feature: Bin - Success
Scenario: Run a successful test
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit --seed 1234 -j spec/jasmine/success/success.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 0
And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage
And the report file "spec/report.txt" should have seed 1234

Scenario: Run a successful test with legacy file reporting
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --report spec/report.txt`
Then the exit status should be 0
And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage

Scenario: Run a successful test with shortened format definition
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --format HeadlessFileReporter:spec/report.txt`
Then the exit status should be 0
And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage

5 changes: 5 additions & 0 deletions features/bin/success_with_js_error.feature
@@ -0,0 +1,5 @@
Feature: Bin - Success with JS Error
Scenario: Succeed
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/success_with_error/success_with_error.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 1
7 changes: 7 additions & 0 deletions features/bin/tries_to_leave_page.feature
@@ -0,0 +1,7 @@
Feature: Bin - Try to Leave Page
Scenario: Fail on trying to leave the page
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/leave_page/leave_page.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 1
And the report file "spec/report.txt" should exist

7 changes: 7 additions & 0 deletions features/bin/try_to_click_a_button.feature
@@ -0,0 +1,7 @@
Feature: Bin - Try to Click A Button
Scenario: Don't leave page when clicking a button
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/click_button/click_button.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 0
And the report file "spec/report.txt" should have 0 total, 0 failures, no console usage

7 changes: 7 additions & 0 deletions features/bin/with_coffeescript_error.feature
@@ -0,0 +1,7 @@
Feature: Bin - With CoffeeScript error
Scenario: Fail on CoffeeScript error
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/coffeescript_error/coffeescript_error.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 1
And the report file "spec/report.txt" should not exist

7 changes: 7 additions & 0 deletions features/bin/with_console_log.feature
@@ -0,0 +1,7 @@
Feature: Bin - With console.log
Scenario: Run a successful test that uses console.log
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/console_log/console_log.yml --format HeadlessFileReporter --out spec/report.txt`
Then the exit status should be 2
And the report file "spec/report.txt" should have 1 total, 0 failures, yes console usage

24 changes: 24 additions & 0 deletions features/reporters.feature
@@ -0,0 +1,24 @@
Feature: Reporters
In order to allow for multiple types of output
I should be able to
Manage reporters and decide which ones to use

Scenario: Use default reporters
Given I have the default runner options
When I get a runner
And I get a template writer
Then the template should use the "HeadlessConsoleReporter" reporter to "stdout"
And the command to run the runner should not include a report file

Scenario: Use a file reporter
Given I have the default runner options
And I have the following reporters:
| Name | File |
| ConsoleReporter | |
| FileReporter | file |
When I get a runner
And I get a template writer
Then the template should use the "ConsoleReporter" reporter to "stdout"
And the template should use the "FileReporter" reporter to "report:0"
And the command to run the runner should include the report file "file"

4 changes: 4 additions & 0 deletions features/steps/given/no_existing_file.rb
@@ -0,0 +1,4 @@
Given /^there is no existing "([^"]*)" file$/ do |file|
FileUtils.rm_rf file
end

4 changes: 4 additions & 0 deletions features/steps/given/options/i_have_defaults.rb
@@ -0,0 +1,4 @@
Given /^I have the default runner options$/ do
@options = Jasmine::Headless::Options.new
end

10 changes: 10 additions & 0 deletions features/steps/given/options/i_have_reporters.rb
@@ -0,0 +1,10 @@
Given /^I have the following reporters:$/ do |table|
@options[:reporters] = []

table.hashes.each do |hash|
reporter = [ hash['Name'] ]
reporter << hash['File'] if !hash['File'].empty?

@options[:reporters] << reporter
end
end
3 changes: 3 additions & 0 deletions features/steps/then/bin/exit_status_should_be.rb
@@ -0,0 +1,3 @@
Then /^the exit status should be (\d+)$/ do |exitstatus|
$?.exitstatus.should == exitstatus.to_i
end
4 changes: 4 additions & 0 deletions features/steps/then/reporting/report_does_not_exist.rb
@@ -0,0 +1,4 @@
Then /^the report file "([^"]*)" should not exist$/ do |file|
File.file?(file).should be_false
end

3 changes: 3 additions & 0 deletions features/steps/then/reporting/report_should_exist.rb
@@ -0,0 +1,3 @@
Then /^the report file "([^"]*)" should exist$/ do |file|
File.file?(file).should be_true
end
7 changes: 7 additions & 0 deletions features/steps/then/reporting/report_should_have.rb
@@ -0,0 +1,7 @@
Then /^the report file "(.*)" should have (\d+) total, (\d+) failures?, (no|yes) console usage$/ do |file, total, failures, console_usage|
report = Jasmine::Headless::Report.load(file)

report.total.should == total.to_i
report.failed.should == failures.to_i
report.has_used_console?.should == (console_usage == 'yes')
end
4 changes: 4 additions & 0 deletions features/steps/then/reporting/report_should_have_seed.rb
@@ -0,0 +1,4 @@
Then /^the report file "([^"]*)" should have seed (\d+)$/ do |file, seed|
report = Jasmine::Headless::Report.load(file)
report.seed.should == seed.to_i
end
4 changes: 4 additions & 0 deletions features/steps/then/runner/it_should_include_report_file.rb
@@ -0,0 +1,4 @@
Then /^the command to run the runner should include the report file "([^"]*)"$/ do |file|
@runner.jasmine_command.should include("-r #{file}")
end

@@ -0,0 +1,3 @@
Then /^the command to run the runner should not include a report file$/ do
@runner.jasmine_command.should_not include('-r')
end
6 changes: 6 additions & 0 deletions features/steps/then/templates/it_should_use_reporter.rb
@@ -0,0 +1,6 @@
Then /^the template should use the "([^"]*)" reporter to "([^"]*)"$/ do |reporter, target|
output = @template_writer.render

output.should include(%{jasmine.#{reporter}("#{target}")})
end

0 comments on commit 0adf3a4

Please sign in to comment.