diff --git a/.autotest b/.autotest new file mode 100644 index 0000000..e262086 --- /dev/null +++ b/.autotest @@ -0,0 +1,9 @@ +Autotest.add_hook(:initialize) do |at| + at.add_mapping(%r{bin/.*}, true) do |filename| + at.files_matching(%r{spec/bin/.*}) + end + + at.add_mapping(%r{spec/jasmine/.*}, true) do |filename| + at.files_matching(%r{spec/bin/.*}) + end +end diff --git a/.gitignore b/.gitignore index d4de0d1..78852f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ pkg/* Makefile specrunner.moc specrunner.o -jasmine-webkit-specrunner +ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..b71bde1 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +-c diff --git a/Gemfile b/Gemfile index 1bfa24a..403dc97 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,7 @@ source "http://rubygems.org" # Specify your gem's dependencies in jasmine-headless-webkit.gemspec gemspec + +gem 'rspec' +gem 'autotest' + diff --git a/autotest/discover.rb b/autotest/discover.rb new file mode 100644 index 0000000..47355c9 --- /dev/null +++ b/autotest/discover.rb @@ -0,0 +1 @@ +Autotest.add_discovery { 'rspec2' } diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 11a7ca8..b8cc56c 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -64,7 +64,7 @@ HTML File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output } system %{#{File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner')} #{target}} -status = ($? == 0) ? 0 : 1 +status = $?.exitstatus FileUtils.rm_f target exit status diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index a9e220a..97f8b23 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -63,12 +63,14 @@ private: QBasicTimer m_ticker; int m_runs; bool hasErrors; + bool usedConsole; }; HeadlessSpecRunner::HeadlessSpecRunner() : QObject() , m_runs(0) , hasErrors(false) + , usedConsole(false) { m_page.settings()->enablePersistentStorage(); connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); @@ -112,6 +114,7 @@ void HeadlessSpecRunner::errorLog(const QString &msg, int lineNumber, const QStr void HeadlessSpecRunner::log(const QString &msg) { + usedConsole = true; std::cout << "\033[0;32m" << "[console] " << "\033[m"; std::cout << qPrintable(msg); std::cout << std::endl; @@ -160,7 +163,7 @@ void HeadlessSpecRunner::timerEvent(QTimerEvent *event) if (hasElement(".runner.passed")) { QWebElement desc = m_page.mainFrame()->findFirstElement(".description"); std::cout << "\033[0;32m" << "PASS: " << qPrintable(desc.toPlainText()) << "\033[m" << std::endl; - QApplication::instance()->exit(0); + QApplication::instance()->exit(usedConsole ? 2 : 0); return; } diff --git a/index.md b/index.md new file mode 100644 index 0000000..84437f8 --- /dev/null +++ b/index.md @@ -0,0 +1,3 @@ +## here + +whoa, it's headless diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb new file mode 100644 index 0000000..26f4fd8 --- /dev/null +++ b/spec/bin/jasmine-headless-webkit_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe "jasmine-headless-webkit" do + describe 'success' do + it "should succeed with error code 0" do + %x{bin/jasmine-headless-webkit spec/jasmine/success/success.yml} + $?.exitstatus.should == 0 + end + end + + describe 'failure' do + it "should fail with an error code of 1" do + %x{bin/jasmine-headless-webkit spec/jasmine/failure/failure.yml} + $?.exitstatus.should == 1 + 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 spec/jasmine/console_log/console_log.yml} + $?.exitstatus.should == 2 + end + end +end + diff --git a/spec/jasmine/console_log/console_log.js b/spec/jasmine/console_log/console_log.js new file mode 100644 index 0000000..e1e83fb --- /dev/null +++ b/spec/jasmine/console_log/console_log.js @@ -0,0 +1 @@ +var success = 1; diff --git a/spec/jasmine/console_log/console_log.yml b/spec/jasmine/console_log/console_log.yml new file mode 100644 index 0000000..7a2453e --- /dev/null +++ b/spec/jasmine/console_log/console_log.yml @@ -0,0 +1,10 @@ + +src_files: + - spec/jasmine/console_log/console_log.js + +spec_files: + - spec/jasmine/console_log/console_log_spec.js + +src_dir: . +spec_dir: . + diff --git a/spec/jasmine/console_log/console_log_spec.js b/spec/jasmine/console_log/console_log_spec.js new file mode 100644 index 0000000..471396c --- /dev/null +++ b/spec/jasmine/console_log/console_log_spec.js @@ -0,0 +1,7 @@ +describe('console.log', function() { + it('should succeed, but with a console.log', function() { + console.log("hello"); + expect(success).toEqual(1); + }); +}); + diff --git a/spec/jasmine/failure/failure.js b/spec/jasmine/failure/failure.js new file mode 100644 index 0000000..f3c5d5b --- /dev/null +++ b/spec/jasmine/failure/failure.js @@ -0,0 +1 @@ +var failure = 0; diff --git a/spec/jasmine/failure/failure.yml b/spec/jasmine/failure/failure.yml new file mode 100644 index 0000000..b9c7510 --- /dev/null +++ b/spec/jasmine/failure/failure.yml @@ -0,0 +1,9 @@ +src_files: + - spec/jasmine/failure/failure.js + +spec_files: + - spec/jasmine/failure/failure_spec.js + +src_dir: . +spec_dir: . + diff --git a/spec/jasmine/failure/failure_spec.js b/spec/jasmine/failure/failure_spec.js new file mode 100644 index 0000000..2ff2d31 --- /dev/null +++ b/spec/jasmine/failure/failure_spec.js @@ -0,0 +1,6 @@ +describe('failure', function() { + it("should fail with error code of 1", function() { + expect(failure).toEqual(1); + }); +}); + diff --git a/spec/jasmine/success/success.js b/spec/jasmine/success/success.js new file mode 100644 index 0000000..e1e83fb --- /dev/null +++ b/spec/jasmine/success/success.js @@ -0,0 +1 @@ +var success = 1; diff --git a/spec/jasmine/success/success.yml b/spec/jasmine/success/success.yml new file mode 100644 index 0000000..b3d3b62 --- /dev/null +++ b/spec/jasmine/success/success.yml @@ -0,0 +1,9 @@ +src_files: + - spec/jasmine/success/success.js + +spec_files: + - spec/jasmine/success/success_spec.js + +src_dir: . +spec_dir: . + diff --git a/spec/jasmine/success/success_spec.js b/spec/jasmine/success/success_spec.js new file mode 100644 index 0000000..0141004 --- /dev/null +++ b/spec/jasmine/success/success_spec.js @@ -0,0 +1,6 @@ +describe('success', function() { + it("should be a success", function() { + expect(success).toEqual(1); + }); +}); + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..64a326c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,8 @@ +specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner' + +if !File.file?(specrunner) + Dir.chdir File.split(specrunner).first do + system %{ruby extconf.rb} + end +end +