diff --git a/Gemfile b/Gemfile index f04a59b..ec3e2e7 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Guardfile b/Guardfile index 38c2dc6..620fcd4 100644 --- a/Guardfile +++ b/Guardfile @@ -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 diff --git a/Rakefile b/Rakefile index 6f33603..a9c6eb5 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 3ea407a..c5332e6 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -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 iterator(reportFiles); + + while (iterator.hasNext()) { + QFile *outputFile = new QFile(iterator.next()); outputFile->open(QIODevice::WriteOnly); outputFiles.enqueue(outputFile); } @@ -100,8 +102,8 @@ void Runner::hasSpecFailure() { _hasSpecFailure = true; } -void Runner::reportFile(const QString &file) { - reportFileName = file; +void Runner::setReportFiles(QStack &files) { + reportFiles = files; } void Runner::timerPause() { @@ -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); @@ -127,14 +137,12 @@ void Runner::print(const QString &fh, const QString &content) { std::cerr.flush(); } - if (fh == "report") { - QListIterator 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(); } } @@ -150,10 +158,8 @@ void Runner::timerEvent() { QApplication::instance()->exit(1); if (isFinished && runs > 2) { - QListIterator iterator(outputFiles); - - while (iterator.hasNext()) { - iterator.next()->close(); + while (!outputFiles.isEmpty()) { + outputFiles.dequeue()->close(); } int exitCode = 0; diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index f49d5fc..8b65a46 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -20,7 +20,9 @@ class Runner: public QObject { Runner(); void setColors(bool colors); - void reportFile(const QString &file); + void setReportFiles(QStack &files); + void setSeed(QString s); + void addFile(const QString &spec); void go(); @@ -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(); @@ -50,15 +55,14 @@ class Runner: public QObject { bool isFinished; bool useColors; - QQueue runnerFiles; + QString seed; - QString reportFileName; + QQueue runnerFiles; + QStack reportFiles; void loadSpec(); QQueue outputFiles; - - QFile *outputFile; }; #endif diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index c0e969f..22d94ac 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -29,34 +29,40 @@ int main(int argc, char** argv) { - char *reporter = NULL; - char showColors = false; + bool showColors = false; + QString seed; + + QStack 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 ] 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])); diff --git a/features/bin/failure.feature b/features/bin/failure.feature new file mode 100644 index 0000000..aa59fdc --- /dev/null +++ b/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 + diff --git a/features/bin/filtered_run/both_runs.feature b/features/bin/filtered_run/both_runs.feature new file mode 100644 index 0000000..e23156c --- /dev/null +++ b/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 diff --git a/features/bin/filtered_run/no_full_run.feature b/features/bin/filtered_run/no_full_run.feature new file mode 100644 index 0000000..a16553e --- /dev/null +++ b/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 + diff --git a/features/bin/reporters.feature b/features/bin/reporters.feature new file mode 100644 index 0000000..e69de29 diff --git a/features/bin/success.feature b/features/bin/success.feature new file mode 100644 index 0000000..50d0a79 --- /dev/null +++ b/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 + diff --git a/features/bin/success_with_js_error.feature b/features/bin/success_with_js_error.feature new file mode 100644 index 0000000..0cb3da4 --- /dev/null +++ b/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 diff --git a/features/bin/tries_to_leave_page.feature b/features/bin/tries_to_leave_page.feature new file mode 100644 index 0000000..3334159 --- /dev/null +++ b/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 + diff --git a/features/bin/try_to_click_a_button.feature b/features/bin/try_to_click_a_button.feature new file mode 100644 index 0000000..91ff051 --- /dev/null +++ b/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 + diff --git a/features/bin/with_coffeescript_error.feature b/features/bin/with_coffeescript_error.feature new file mode 100644 index 0000000..7b03252 --- /dev/null +++ b/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 + diff --git a/features/bin/with_console_log.feature b/features/bin/with_console_log.feature new file mode 100644 index 0000000..47ce1e8 --- /dev/null +++ b/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 + diff --git a/features/reporters.feature b/features/reporters.feature new file mode 100644 index 0000000..fe10131 --- /dev/null +++ b/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" + diff --git a/features/steps/given/no_existing_file.rb b/features/steps/given/no_existing_file.rb new file mode 100644 index 0000000..04a8b15 --- /dev/null +++ b/features/steps/given/no_existing_file.rb @@ -0,0 +1,4 @@ +Given /^there is no existing "([^"]*)" file$/ do |file| + FileUtils.rm_rf file +end + diff --git a/features/steps/given/options/i_have_defaults.rb b/features/steps/given/options/i_have_defaults.rb new file mode 100644 index 0000000..03e7971 --- /dev/null +++ b/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 + diff --git a/features/steps/given/options/i_have_reporters.rb b/features/steps/given/options/i_have_reporters.rb new file mode 100644 index 0000000..60ffb68 --- /dev/null +++ b/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 diff --git a/features/steps/then/bin/exit_status_should_be.rb b/features/steps/then/bin/exit_status_should_be.rb new file mode 100644 index 0000000..0e6992c --- /dev/null +++ b/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 diff --git a/features/steps/then/reporting/report_does_not_exist.rb b/features/steps/then/reporting/report_does_not_exist.rb new file mode 100644 index 0000000..2cff304 --- /dev/null +++ b/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 + diff --git a/features/steps/then/reporting/report_should_exist.rb b/features/steps/then/reporting/report_should_exist.rb new file mode 100644 index 0000000..d7b5859 --- /dev/null +++ b/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 diff --git a/features/steps/then/reporting/report_should_have.rb b/features/steps/then/reporting/report_should_have.rb new file mode 100644 index 0000000..ef2ad58 --- /dev/null +++ b/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 diff --git a/features/steps/then/reporting/report_should_have_seed.rb b/features/steps/then/reporting/report_should_have_seed.rb new file mode 100644 index 0000000..ec905a3 --- /dev/null +++ b/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 diff --git a/features/steps/then/runner/it_should_include_report_file.rb b/features/steps/then/runner/it_should_include_report_file.rb new file mode 100644 index 0000000..0dd465a --- /dev/null +++ b/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 + diff --git a/features/steps/then/runner/it_should_not_include_report_file.rb b/features/steps/then/runner/it_should_not_include_report_file.rb new file mode 100644 index 0000000..28a7417 --- /dev/null +++ b/features/steps/then/runner/it_should_not_include_report_file.rb @@ -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 diff --git a/features/steps/then/templates/it_should_use_reporter.rb b/features/steps/then/templates/it_should_use_reporter.rb new file mode 100644 index 0000000..5e9e99e --- /dev/null +++ b/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 + diff --git a/features/steps/when/i_get_runner.rb b/features/steps/when/i_get_runner.rb new file mode 100644 index 0000000..ed1b2e6 --- /dev/null +++ b/features/steps/when/i_get_runner.rb @@ -0,0 +1,4 @@ +When /^I get a runner$/ do + @runner = Jasmine::Headless::Runner.new(@options) +end + diff --git a/features/steps/when/i_get_template_writer.rb b/features/steps/when/i_get_template_writer.rb new file mode 100644 index 0000000..77c1e2c --- /dev/null +++ b/features/steps/when/i_get_template_writer.rb @@ -0,0 +1,4 @@ +When /^I get a template writer$/ do + @template_writer = Jasmine::Headless::TemplateWriter.new(@runner) +end + diff --git a/features/steps/when/i_run_executable.rb b/features/steps/when/i_run_executable.rb new file mode 100644 index 0000000..553ef51 --- /dev/null +++ b/features/steps/when/i_run_executable.rb @@ -0,0 +1,4 @@ +When /^I run `(.*)`$/ do |command| + system command +end + diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..db7b786 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,2 @@ +require 'jasmine-headless-webkit' + diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index e819ac2..5a5a9eb 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -72,7 +72,9 @@ module Jasmine::Headless def default_files %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessReporter - jasmine.HeadlessFileReporter jasmine.HeadlessConsoleReporter jsDump beautify-html} + jasmine.HeadlessFileReporter jasmine.HeadlessConsoleReporter + jasmine.HeadlessTAPReporter + jsDump beautify-html} end def extension_filter @@ -84,7 +86,7 @@ module Jasmine::Headless PLEASE_WAIT_IM_WORKING_TIME = 2 - attr_reader :required_files, :potential_files_to_filter + attr_reader :options, :required_files, :potential_files_to_filter def initialize(options = {}) @options = options @@ -184,16 +186,12 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME - p self.class.extension_filter - files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end - p file - sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index a228dd6..7f85f2c 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -13,7 +13,6 @@ module Jasmine :remove_html_file => true, :runner_output_filename => false, :jasmine_config => 'spec/javascripts/support/jasmine.yml', - :report => false, :do_list => false, :full_run => true, :enable_cache => true, @@ -26,6 +25,8 @@ module Jasmine DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') GLOBAL_DEFAULTS_FILE = File.expand_path('~/.jasmine-headless-webkit') + REPORT_DEPRECATED_MESSAGE = "--report is deprecated. Use --format HeadlessFileReporter --out " + def self.from_command_line options = new options.process_command_line_args @@ -56,7 +57,10 @@ module Jasmine when '--keep' @options[:remove_html_file] = false when '--report' - @options[:report] = arg + warn REPORT_DEPRECATED_MESSAGE + + add_reporter('HeadlessFileReporter', arg) + add_reporter('HeadlessConsoleReporter') when '--runner-out' @options[:runner_output_filename] = arg when '--jasmine-config', '-j' @@ -70,7 +74,7 @@ module Jasmine when '--format', '-f' add_reporter(arg) when '--out' - @options[:reporters].last << arg + add_reporter_file(arg) end end @@ -119,14 +123,28 @@ module Jasmine end end + def file_reporters + reporters.find_all { |reporter| reporter[1]["report:"] } + end + private - def add_reporter(name) + def add_reporter(name, file = nil) if !@added_reporter @options[:reporters] = [] @added_reporter = true end + if (parts = name.split(':')).length == 2 + name, file = parts + end + @options[:reporters] << [ name ] + + add_reporter_file(file) if file + end + + def add_reporter_file(file) + @options[:reporters].last << file end end end diff --git a/lib/jasmine/headless/report.rb b/lib/jasmine/headless/report.rb index d620b73..3da241c 100644 --- a/lib/jasmine/headless/report.rb +++ b/lib/jasmine/headless/report.rb @@ -60,8 +60,13 @@ module Jasmine::Headless }.collect(&:filename).uniq.compact end - private + def seed + if seed = report.find { |entry| entry.respond_to?(:seed) } + seed.seed + end + end + private def last_total @report.reverse.find { |entry| entry.respond_to?(:total) } end diff --git a/lib/jasmine/headless/report_message.rb b/lib/jasmine/headless/report_message.rb index 218ba17..83505a4 100644 --- a/lib/jasmine/headless/report_message.rb +++ b/lib/jasmine/headless/report_message.rb @@ -6,6 +6,7 @@ module Jasmine::Headless autoload :Console, 'jasmine/headless/report_message/console' autoload :Error, 'jasmine/headless/report_message/error' autoload :Total, 'jasmine/headless/report_message/total' + autoload :Seed, 'jasmine/headless/report_message/seed' end end diff --git a/lib/jasmine/headless/report_message/console.rb b/lib/jasmine/headless/report_message/console.rb index 25c64ef..2fb8e85 100644 --- a/lib/jasmine/headless/report_message/console.rb +++ b/lib/jasmine/headless/report_message/console.rb @@ -1,9 +1,7 @@ module Jasmine::Headless::ReportMessage class Console - class << self - def new_from_parts(parts) - new(parts.first) - end + def self.new_from_parts(parts) + new(parts.first) end attr_reader :message diff --git a/lib/jasmine/headless/report_message/seed.rb b/lib/jasmine/headless/report_message/seed.rb new file mode 100644 index 0000000..a2f53f2 --- /dev/null +++ b/lib/jasmine/headless/report_message/seed.rb @@ -0,0 +1,14 @@ +module Jasmine::Headless::ReportMessage + class Seed + def self.new_from_parts(parts) + new(parts.first) + end + + attr_reader :seed + + def initialize(seed) + @seed = seed.to_i + end + end +end + diff --git a/lib/jasmine/headless/report_message/spec.rb b/lib/jasmine/headless/report_message/spec.rb index 63c5b54..218dabd 100644 --- a/lib/jasmine/headless/report_message/spec.rb +++ b/lib/jasmine/headless/report_message/spec.rb @@ -1,11 +1,9 @@ module Jasmine::Headless::ReportMessage class Spec - class << self - def new_from_parts(parts) - file_info = parts.pop + def self.new_from_parts(parts) + file_info = parts.pop - new(parts.join(' '), file_info) - end + new(parts.join(' '), file_info) end attr_reader :statement, :file_info diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 85763c8..946fe71 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -34,14 +34,6 @@ module Jasmine end def initialize(options) - if !File.file?(RUNNER) - $stderr.puts "No runner found, attempting to compile..." - Dir.chdir RUNNER_DIR do - system %{ruby extconf.rb} - end - raise NoRunnerError if !File.file?(RUNNER) - end - @options = options end @@ -60,25 +52,25 @@ module Jasmine end def jasmine_command(*targets) - [ - RUNNER, - @options[:colors] ? '-c' : nil, - @options[:report] ? "-r #{@options[:report]}" : nil, - *targets - ].compact.join(" ") + command = [ RUNNER ] + + command << "-s #{options[:seed]}" + command << '-c' if options[:colors] + + options.file_reporters.each do |reporter, identifier, file| + command << "-r #{file}" + end + + command += targets + + command.compact.join(' ') end def run Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache] FilesList.reset! - files_list = Jasmine::Headless::FilesList.new( - :config => jasmine_config, - :only => @options[:files], - :seed => @options[:seed] - ) - - @_targets = template_writer.write!(files_list) + @_targets = template_writer.write run_targets = @_targets.dup @@ -90,8 +82,6 @@ module Jasmine system jasmine_command(run_targets) - puts "\nTest ordering seed: --seed #{@options[:seed]}" - @_status = $?.exitstatus ensure if @_targets && !runner_filename && (@options[:remove_html_file] || (@_status == 0)) @@ -109,6 +99,14 @@ module Jasmine end end + def files_list + @files_list ||= Jasmine::Headless::FilesList.new( + :config => jasmine_config, + :only => @options[:files], + :seed => @options[:seed] + ) + end + private def jasmine_config_data raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) diff --git a/lib/jasmine/headless/template_writer.rb b/lib/jasmine/headless/template_writer.rb index 7d41161..1592265 100644 --- a/lib/jasmine/headless/template_writer.rb +++ b/lib/jasmine/headless/template_writer.rb @@ -1,24 +1,30 @@ require 'multi_json' require 'erb' require 'tempfile' +require 'forwardable' module Jasmine::Headless class TemplateWriter attr_reader :runner + extend Forwardable + + def_delegators :runner, :files_list, :options + def_delegators :options, :reporters + def initialize(runner) @runner = runner end - def write!(files_list) + def write output = [ [ all_tests_filename, files_list.files_to_html ] ] - output.unshift([filtered_tests_filename , files_list.filtered_files_to_html ]) if files_list.filtered? + output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered? output.each do |name, files| - File.open(name, 'w') { |fh| fh.print template_for(files, files_list.spec_file_line_numbers) } + File.open(name, 'w') { |fh| fh.print template_for(files) } end output.collect(&:first) @@ -32,8 +38,24 @@ module Jasmine::Headless all_tests_filename.gsub(%r{\.html$}, '.filter.html') end + def render + template_for(all_files) + end + + def all_files + files_list.files_to_html + end + + def jhw_reporters + reporters.collect do |reporter, output| + %{jasmine.getEnv().addReporter(new jasmine.#{reporter}("#{output}"));} + end.join("\n") + end + private - def template_for(files, spec_lines) + def template_for(files) + spec_lines = files_list.spec_file_line_numbers + ERB.new(Jasmine::Headless.root.join('skel/template.html.erb').read).result(binding) end end diff --git a/skel/template.html.erb b/skel/template.html.erb index 10e5307..c02247b 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -12,7 +12,7 @@