From 879975a8cac9327aba0442ac2641a0d5d93405c9 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 18 Jul 2011 10:52:57 -0400 Subject: [PATCH 01/20] better qt building? --- ext/jasmine-webkit-specrunner/extconf.rb | 12 +- lib/qt/qmake.rb | 143 +++++++++++++++++++++++ spec/lib/qt/qmake_spec.rb | 93 +++++++++++++++ 3 files changed, 241 insertions(+), 7 deletions(-) create mode 100644 lib/qt/qmake.rb create mode 100644 spec/lib/qt/qmake_spec.rb diff --git a/ext/jasmine-webkit-specrunner/extconf.rb b/ext/jasmine-webkit-specrunner/extconf.rb index cbc77ca..6cb0252 100644 --- a/ext/jasmine-webkit-specrunner/extconf.rb +++ b/ext/jasmine-webkit-specrunner/extconf.rb @@ -1,8 +1,6 @@ -case RUBY_PLATFORM -when /linux/ - system %{qmake -spec linux-g++} -else - system %{qmake -spec macx-g++} -end +$: << File.expand_path("../../../lib", __FILE__) + +require 'qt/qmake' + +Qt::Qmake.make!('jasmine-headless-webkit') -system %{make} diff --git a/lib/qt/qmake.rb b/lib/qt/qmake.rb new file mode 100644 index 0000000..e1ce112 --- /dev/null +++ b/lib/qt/qmake.rb @@ -0,0 +1,143 @@ +require 'rbconfig' + +module Qt + class NotInstalledError < StandardError; end + + class Qmake + class << self + def installed? + path != nil + end + + def make_installed? + make_path != nil + end + + def command + case platform + when :linux + "#{path} -spec linux-g++" + when :mac_os_x + "#{path} -spec macx-g++" + end + end + + def make!(name) + @name = name + + check_make! + check_qmake! + check_qmake_version! + + system command + system %{make} + end + + # + # We need integration tests for these! + # + def path + get_exe_path('qmake') + end + + def make_path + get_exe_path('make') + end + + def platform + case RbConfig::CONFIG['host_os'] + when /linux/ + :linux + when /darwin/ + :mac_os_x + end + end + + def qt_version + @qt_version ||= %x{#{path} -v}.lines.to_a[1][%r{Using Qt version ([^ ]+) },1] + end + + def qt_47_or_better? + return false if !qt_version + return true if (major = qt_version.split('.')[0].to_i) > 4 + return false if major < 4 + qt_version.split('.')[1].to_i >= 7 + end + + private + def get_exe_path(command) + path = %x{which #{command}}.strip + path = nil if path == '' + path + end + + def check_make! + if !make_installed? + install_method = ( + case platform + when :linux + %{sudo apt-get install make or sudo yum install make} + when :darwin + %{Install XCode, and/or sudo port install make} + end + ) + + $stderr.puts <<-MSG +make is not installed. You'll need to install it to build #{@name}. +#{install_method} should do it for you. +MSG + raise NotInstalledError + end + end + + def check_qmake! + if !installed? + install_method = strip( + case platform + when :linux + <<-MSG +sudo apt-get install libqt4-dev qt4-qmake on Debian-based systems, or downloading +Nokia's prebuilt binary at http://qt.nokia.com/downloads/ +MSG + when :darwin + <<-MSG +sudo port install qt4-mac (for the patient) or downloading Nokia's pre-built binary +at http://qt.nokia.com/downloads/ +MSG + end + ) + + $stderr.puts <<-MSG +qmake is not installed. You'll need to install it to build #{@name}. +#{install_method} should do it for you. +MSG + end + end + + def check_qmake_version! + if !qt_47_or_better? + install_method = strip( + case platform + when :linux + <<-MSG +sudo apt-get install libqt4-dev qt4-qmake on Debian-based systems, or downloading +Nokia's prebuilt binary at http://qt.nokia.com/downloads/ +MSG + when :darwin + <<-MSG +sudo port install qt4-mac (for the patient) or downloading Nokia's pre-built binary +at http://qt.nokia.com/downloads/ +MSG + end + ) + + $stderr.puts <<-MSG +qmake is not version 4.7 or above (currently version #{qt_version}. You'll need to install version 4.7 or higher +to build #{@name}. #{install_method} should do it for you. +MSG + end + end + end + end +end + diff --git a/spec/lib/qt/qmake_spec.rb b/spec/lib/qt/qmake_spec.rb new file mode 100644 index 0000000..41a0862 --- /dev/null +++ b/spec/lib/qt/qmake_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' +require 'qt/qmake' +require 'rbconfig' + +describe Qt::Qmake do + describe '.make_installed?' do + subject { described_class } + + before do + Qt::Qmake.stubs(:make_path).returns(path) + end + + context 'not installed' do + let(:path) { nil } + + it { should_not be_make_installed } + end + + context 'installed' do + let(:path) { '/here/there/make' } + + it { should be_make_installed } + end + end + + describe '.installed?' do + subject { described_class } + + before do + Qt::Qmake.stubs(:path).returns(path) + end + + context 'not installed' do + let(:path) { nil } + + it { should_not be_installed } + end + + context 'installed' do + let(:path) { '/here/there/qmake' } + + it { should be_installed } + end + end + + describe '.command' do + subject { described_class.command } + + before do + Qt::Qmake.stubs(:platform).returns(platform) + Qt::Qmake.stubs(:path).returns("qmake") + end + + context 'linux' do + let(:platform) { :linux } + + it { should == "qmake -spec linux-g++" } + end + + context 'mac os x' do + let(:platform) { :mac_os_x } + + it { should == "qmake -spec macx-g++" } + end + end + + describe '.qt_47_or_better?' do + subject { described_class } + + before do + Qt::Qmake.stubs(:qt_version).returns(version) + end + + context 'no version' do + let(:version) { nil } + + it { should_not be_qt_47_or_better } + end + + context 'not better' do + let(:version) { '4.6.0' } + + it { should_not be_qt_47_or_better } + end + + context 'better' do + let(:version) { '4.7.0' } + + it { should be_qt_47_or_better } + end + end +end + -- 2.45.2 From 21d93e7c9fd08b881b808c6189b299274e3e0521 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 19 Jul 2011 09:54:39 -0400 Subject: [PATCH 02/20] set application name to silence phonon warnings --- Gemfile | 2 +- ext/jasmine-webkit-specrunner/specrunner.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5705358..c16218b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source :rubygems # Specify your gem's dependencies in jasmine-headless-webkit.gemspec gemspec diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index 2b3a00b..1a52982 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -380,6 +380,7 @@ int main(int argc, char** argv) } QApplication app(argc, argv); + app.setApplicationName("jasmine-headless-webkit"); HeadlessSpecRunner runner; runner.setColors(showColors); runner.reportFile(reporter); -- 2.45.2 From 75f4d2634420cf62a8cc56d105e769dab67c45b6 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 19 Jul 2011 10:29:25 -0400 Subject: [PATCH 03/20] better handling of rails version checks --- lib/jasmine/headless/task.rb | 2 +- spec/lib/jasmine/headless/task_spec.rb | 28 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/jasmine/headless/task.rb b/lib/jasmine/headless/task.rb index a727378..113030e 100644 --- a/lib/jasmine/headless/task.rb +++ b/lib/jasmine/headless/task.rb @@ -42,7 +42,7 @@ module Jasmine private def create_rails_compliant_task - if Rails.version >= "3.1.0" + if Rails.respond_to?(:version) && Rails.version >= "3.1.0" desc 'Force generate static assets without an MD5 hash, all assets end with -test.' task 'assets:precompile:for_testing' => :environment do Rails.application.assets.digest_class = Digest::JasmineTest diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb index a6dc643..0f5d791 100644 --- a/spec/lib/jasmine/headless/task_spec.rb +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -21,16 +21,32 @@ describe Jasmine::Headless::Task do end context 'with Rails' do - before do - module Rails - def self.version - return "0" + context 'without version' do + before do + module Rails + def self.version + return "0" + end end end + + it 'should be OK if rails is defined' do + Jasmine::Headless::Task.new('jasmine:headless') + end end - it 'should be OK if rails is defined' do - Jasmine::Headless::Task.new('jasmine:headless') + context 'with version' do + before do + module Rails + def self.version + return "0" + end + end + end + + it 'should be OK if rails is defined' do + Jasmine::Headless::Task.new('jasmine:headless') + end end end end -- 2.45.2 From 4c7e03dc5738a9a7842107bfcfc703dbe0fccb87 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 19 Jul 2011 10:41:23 -0400 Subject: [PATCH 04/20] we don't need all of jasmine, just jasmine-core --- Rakefile | 6 ++++++ jasmine-headless-webkit.gemspec | 2 +- lib/jasmine/files_list.rb | 11 +---------- lib/jasmine/headless/runner.rb | 1 - 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 47c0fb7..02ec64b 100644 --- a/Rakefile +++ b/Rakefile @@ -38,3 +38,9 @@ end task :default => [ 'spec:platforms', 'jasmine:headless' ] +desc "Build the runner" +task :build do + Dir.chdir 'ext/jasmine-headless-specrunner' do + system %{ruby extconf.rb} + end +end diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec index dc2cb46..17aeb06 100644 --- a/jasmine-headless-webkit.gemspec +++ b/jasmine-headless-webkit.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'jasmine', '~>1.1.beta' + s.add_dependency 'jasmine-core', '~>1.1.beta' s.add_dependency 'coffee-script', '>= 2.2' s.add_dependency 'rainbow' s.add_dependency 'multi_json' diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index 9f0c8d3..b1313f4 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -1,13 +1,4 @@ -begin - require 'jasmine' -rescue NameError => e - if e.message['ActiveSupport::Concern'] - $stderr.puts "[%s] %s (%s)" % [ "jasmine-gem".color(:red), e.message.color(:white), e.class.name.color(:yellow) ] - $stderr.puts "#{'Jasmine'.color(:red)} believes Rails 3 is available. Try using #{'Bundler'.color(:green)} and running via #{'bundle exec'.color(:green)}." - else - raise e - end -end +require 'jasmine-core' module Jasmine class FilesList diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index a9d48a0..4be91c9 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -3,7 +3,6 @@ require 'jasmine/headless/options' require 'fileutils' -require 'jasmine/base' require 'coffee-script' require 'rainbow' -- 2.45.2 From 132d9355bd64dea262ce790ece9a70e3cbcce6bf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 19 Jul 2011 10:47:24 -0400 Subject: [PATCH 05/20] changes and hooks and junk --- CHANGELOG.md | 1 + dev-bin/hooks/pre-commit | 5 +++++ dev-bin/install-hooks | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100755 dev-bin/hooks/pre-commit create mode 100755 dev-bin/install-hooks diff --git a/CHANGELOG.md b/CHANGELOG.md index 7844fcf..60b8156 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * File and line number information for failing specs * Try to build the runner if it's missing +* Kill warnings and streamline includes ## 0.5.0 diff --git a/dev-bin/hooks/pre-commit b/dev-bin/hooks/pre-commit new file mode 100755 index 0000000..75c11e3 --- /dev/null +++ b/dev-bin/hooks/pre-commit @@ -0,0 +1,5 @@ +#!/bin/bash + +bundle exec rake +if [ $? -ne 0 ]; then exit 1; fi + diff --git a/dev-bin/install-hooks b/dev-bin/install-hooks new file mode 100755 index 0000000..5a7809c --- /dev/null +++ b/dev-bin/install-hooks @@ -0,0 +1,6 @@ +#!/bin/bash + +for i in $PWD/dev-bin/hooks/*; do + ln -sf $i .git/hooks/${i##*/} +done + -- 2.45.2 From f77bfb1705717604e855b4f068537c7019662167 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jul 2011 09:26:01 -0400 Subject: [PATCH 06/20] changelog and minor version bump --- CHANGELOG.md | 4 +++- lib/jasmine-headless-webkit/version.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7844fcf..5aa3827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -## 0.5.1 +## 0.6.0 * File and line number information for failing specs * Try to build the runner if it's missing +* Smarter directions on getting the right version of Qt installed +* Various bugfixes for things ## 0.5.0 diff --git a/lib/jasmine-headless-webkit/version.rb b/lib/jasmine-headless-webkit/version.rb index 6adea70..eba381d 100644 --- a/lib/jasmine-headless-webkit/version.rb +++ b/lib/jasmine-headless-webkit/version.rb @@ -1,7 +1,7 @@ module Jasmine module Headless module Webkit - VERSION = "0.5.1" + VERSION = "0.6.0" end end end -- 2.45.2 From fe18d2a3fd171a82a6758f7aa9093fdcea8efcfd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jul 2011 09:30:30 -0400 Subject: [PATCH 07/20] bump version --- lib/jasmine-headless-webkit/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jasmine-headless-webkit/version.rb b/lib/jasmine-headless-webkit/version.rb index eba381d..8c0e0e8 100644 --- a/lib/jasmine-headless-webkit/version.rb +++ b/lib/jasmine-headless-webkit/version.rb @@ -1,7 +1,7 @@ module Jasmine module Headless module Webkit - VERSION = "0.6.0" + VERSION = "0.6.1" end end end -- 2.45.2 From 8f98da4767081e9f494dc12d97b7a05e5cd0b80e Mon Sep 17 00:00:00 2001 From: Olivier Melcher Date: Wed, 20 Jul 2011 15:27:20 -0700 Subject: [PATCH 08/20] require yaml in runner.rb fixes bad YAML module look-up that would give the following error: [jasmine-headless-webkit] uninitialized constant Jasmine::Headless::Runner::YAML (NameError) /gems/jasmine-headless-webkit-0.6.0/lib/jasmine/headless/runner.rb:47:in `jasmine_config' --- lib/jasmine/headless/runner.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 4be91c9..e4757d7 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -9,6 +9,8 @@ require 'rainbow' require 'jasmine/files_list' require 'jasmine/template_writer' +require 'yaml' + module Jasmine module Headless class Runner -- 2.45.2 From 13bcd5226e6a5463335e5afbf6dbc413baec8b55 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 22 Jul 2011 07:42:25 -0400 Subject: [PATCH 09/20] ensure a spec can't leave the page, causing a craaaazy loop --- ext/jasmine-webkit-specrunner/specrunner.cpp | 37 ++++++++++++++++++-- jasmine/jasmine.headless-reporter.coffee | 3 +- jasmine/jasmine.headless-reporter.js | 6 +++- lib/jasmine/template_writer.rb | 14 +++++++- spec/bin/jasmine-headless-webkit_spec.rb | 9 +++++ spec/jasmine/leave_page/leave_page.js | 4 +++ spec/jasmine/leave_page/leave_page.yml | 9 +++++ spec/jasmine/leave_page/leave_page_spec.js | 11 ++++++ 8 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 spec/jasmine/leave_page/leave_page.js create mode 100644 spec/jasmine/leave_page/leave_page.yml create mode 100644 spec/jasmine/leave_page/leave_page_spec.js diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index 1a52982..d6b0c3c 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -35,6 +35,9 @@ class HeadlessSpecRunnerPage: public QWebPage { Q_OBJECT +public: + HeadlessSpecRunnerPage(); + void oneFalseConfirm(); signals: void consoleLog(const QString &msg, int lineNumber, const QString &sourceID); void internalLog(const QString ¬e, const QString &msg); @@ -42,8 +45,17 @@ protected: void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); bool javaScriptConfirm(QWebFrame *frame, const QString &msg); void javaScriptAlert(QWebFrame *frame, const QString &msg); +private: + bool confirmResult; }; +HeadlessSpecRunnerPage::HeadlessSpecRunnerPage() + : QWebPage() + , confirmResult(true) +{ + +} + void HeadlessSpecRunnerPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) { emit consoleLog(message, lineNumber, sourceID); @@ -51,8 +63,13 @@ void HeadlessSpecRunnerPage::javaScriptConsoleMessage(const QString &message, in bool HeadlessSpecRunnerPage::javaScriptConfirm(QWebFrame *frame, const QString &msg) { - emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); - return true; + if (confirmResult) { + emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); + return true; + } else { + confirmResult = true; + return false; + } } void HeadlessSpecRunnerPage::javaScriptAlert(QWebFrame *frame, const QString &msg) @@ -60,6 +77,11 @@ void HeadlessSpecRunnerPage::javaScriptAlert(QWebFrame *frame, const QString &ms emit internalLog("alert", msg); } +void HeadlessSpecRunnerPage::oneFalseConfirm() +{ + confirmResult = false; +} + class HeadlessSpecRunner: public QObject { Q_OBJECT @@ -71,6 +93,7 @@ public: void go(); public slots: void log(const QString &msg); + void leavePageAttempt(const QString &msg); void specPassed(); void specFailed(const QString &specDetail); void printName(const QString &name); @@ -250,6 +273,16 @@ void HeadlessSpecRunner::log(const QString &msg) std::cout << std::endl; } +void HeadlessSpecRunner::leavePageAttempt(const QString &msg) +{ + red(); + std::cout << "[error] "; + clear(); + std::cout << qPrintable(msg) << std::endl; + m_page.oneFalseConfirm(); + hasErrors = true; +} + void HeadlessSpecRunner::printName(const QString &name) { std::cout << std::endl << std::endl; diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index 447c102..b759f64 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -50,7 +50,7 @@ jasmine.Spec.prototype.getSpecSplitName = -> parts class jasmine.HeadlessReporter - constructor: -> + constructor: (@callback = null) -> @results = [] @failedCount = 0 @length = 0 @@ -59,6 +59,7 @@ class jasmine.HeadlessReporter do (result) => result.print() + this.callback() if @callback JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount) reportRunnerStarting: (runner) -> @startTime = new Date() diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index d9b4eb5..53f2be2 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -83,7 +83,8 @@ return parts; }; jasmine.HeadlessReporter = (function() { - function HeadlessReporter() { + function HeadlessReporter(callback) { + this.callback = callback != null ? callback : null; this.results = []; this.failedCount = 0; this.length = 0; @@ -98,6 +99,9 @@ result = _ref[_i]; _fn(result); } + if (this.callback) { + this.callback(); + } return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount); }; HeadlessReporter.prototype.reportRunnerStarting = function(runner) { diff --git a/lib/jasmine/template_writer.rb b/lib/jasmine/template_writer.rb index 6a99ca4..762dd7e 100644 --- a/lib/jasmine/template_writer.rb +++ b/lib/jasmine/template_writer.rb @@ -31,6 +31,16 @@ module Jasmine }, pp: function(data) { JHW.log(jasmine ? jasmine.pp(data) : JSON.stringify(data)); } }; + + window.onbeforeunload = function(e) { + JHW.leavePageAttempt('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); + + if (e = e || window.event) { + e.returnValue = "leaving"; + } + + return "leaving"; + }; #{files.join("\n")} diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb index cee4707..c40590d 100644 --- a/spec/bin/jasmine-headless-webkit_spec.rb +++ b/spec/bin/jasmine-headless-webkit_spec.rb @@ -60,6 +60,15 @@ describe "jasmine-headless-webkit" do end end + describe 'tries to leave page' do + it "should not leave the page nor loop" do + system %{bin/jasmine-headless-webkit -j spec/jasmine/leave_page/leave_page.yml --report #{report}} + $?.exitstatus.should == 1 + + report.should be_a_report_containing(2, 0, false) + end + end + describe 'with filtered run' do context "don't run a full run, just the filtered run" do it "should succeed and run both" do diff --git a/spec/jasmine/leave_page/leave_page.js b/spec/jasmine/leave_page/leave_page.js new file mode 100644 index 0000000..22f336b --- /dev/null +++ b/spec/jasmine/leave_page/leave_page.js @@ -0,0 +1,4 @@ +function yes() { + document.location.href = 'http://www.google.com/' +} + diff --git a/spec/jasmine/leave_page/leave_page.yml b/spec/jasmine/leave_page/leave_page.yml new file mode 100644 index 0000000..f434433 --- /dev/null +++ b/spec/jasmine/leave_page/leave_page.yml @@ -0,0 +1,9 @@ +src_files: + - spec/jasmine/leave_page/leave_page.js + +spec_files: + - spec/jasmine/leave_page/leave_page_spec.js + +src_dir: . +spec_dir: . + diff --git a/spec/jasmine/leave_page/leave_page_spec.js b/spec/jasmine/leave_page/leave_page_spec.js new file mode 100644 index 0000000..6593c00 --- /dev/null +++ b/spec/jasmine/leave_page/leave_page_spec.js @@ -0,0 +1,11 @@ +describe("something", function() { + it("should be true", function() { + yes(); + expect(true).toEqual(true); + }); + + it("should so something else", function() { + expect(true).toEqual(true); + }); +}); + -- 2.45.2 From d08fb1d44575e94160d537a22de02909c63de9ac Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 22 Jul 2011 07:48:19 -0400 Subject: [PATCH 10/20] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f4b29e..e733ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.6.1 + +* Ensure YAML is loaded before use +* Make sure specs can't break out of the page they're running in + ## 0.6.0 * File and line number information for failing specs -- 2.45.2 From 8a5121bd90557c4eee8cd1c35acbc8e1180a24fb Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 22 Jul 2011 09:40:40 -0400 Subject: [PATCH 11/20] small clenaup and ensure form submits don't trigger loops, either --- jasmine/jasmine.headless-reporter.coffee | 11 ++++----- jasmine/jasmine.headless-reporter.js | 23 ++++++------------- spec/bin/jasmine-headless-webkit_spec.rb | 9 ++++++++ spec/jasmine/click_button/click_button.js | 5 ++++ spec/jasmine/click_button/click_button.yml | 12 ++++++++++ .../jasmine/click_button/click_button_spec.js | 11 +++++++++ spec/javascripts/support/jquery-1.6.2.min.js | 18 +++++++++++++++ 7 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 spec/jasmine/click_button/click_button.js create mode 100644 spec/jasmine/click_button/click_button.yml create mode 100644 spec/jasmine/click_button/click_button_spec.js create mode 100644 spec/javascripts/support/jquery-1.6.2.min.js diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index b759f64..45ec549 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -13,8 +13,7 @@ class window.HeadlessReporterResult JHW.printName(output) for result in @results - do (result) => - JHW.printResult(result) + JHW.printResult(result) _findSpecLine: -> bestChoice = { accuracy: 0, file: null, lineNumber: null } @@ -56,8 +55,7 @@ class jasmine.HeadlessReporter @length = 0 reportRunnerResults: (runner) -> for result in @results - do (result) => - result.print() + result.print() this.callback() if @callback JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount) @@ -73,9 +71,8 @@ class jasmine.HeadlessReporter @failedCount++ failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) for result in results.getItems() - do (result) => - if result.type == 'expect' and !result.passed_ - failureResult.addResult(result.message) + if result.type == 'expect' and !result.passed_ + failureResult.addResult(result.message) @results.push(failureResult) reportSpecStarting: (spec) -> reportSuiteResults: (suite) -> diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 53f2be2..b95b23c 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -1,5 +1,4 @@ (function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; if (!(typeof jasmine !== "undefined" && jasmine !== null)) { throw new Error("jasmine not laoded!"); } @@ -24,9 +23,7 @@ _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; - _results.push(__bind(function(result) { - return JHW.printResult(result); - }, this)(result)); + _results.push(JHW.printResult(result)); } return _results; }; @@ -90,14 +87,11 @@ this.length = 0; } HeadlessReporter.prototype.reportRunnerResults = function(runner) { - var result, _fn, _i, _len, _ref; + var result, _i, _len, _ref; _ref = this.results; - _fn = __bind(function(result) { - return result.print(); - }, this); for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; - _fn(result); + result.print(); } if (this.callback) { this.callback(); @@ -108,7 +102,7 @@ return this.startTime = new Date(); }; HeadlessReporter.prototype.reportSpecResults = function(spec) { - var failureResult, result, results, _fn, _i, _len, _ref; + var failureResult, result, results, _i, _len, _ref; results = spec.results(); this.length++; if (results.passed()) { @@ -118,14 +112,11 @@ this.failedCount++; failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()); _ref = results.getItems(); - _fn = __bind(function(result) { - if (result.type === 'expect' && !result.passed_) { - return failureResult.addResult(result.message); - } - }, this); for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; - _fn(result); + if (result.type === 'expect' && !result.passed_) { + failureResult.addResult(result.message); + } } return this.results.push(failureResult); } diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb index c40590d..d079c93 100644 --- a/spec/bin/jasmine-headless-webkit_spec.rb +++ b/spec/bin/jasmine-headless-webkit_spec.rb @@ -69,6 +69,15 @@ describe "jasmine-headless-webkit" do end end + describe 'tries to click a button' do + it "should not leave the page nor loop" do + system %{bin/jasmine-headless-webkit -j spec/jasmine/click_button/click_button.yml --report #{report}} + $?.exitstatus.should == 1 + + report.should be_a_report_containing(2, 0, false) + end + end + describe 'with filtered run' do context "don't run a full run, just the filtered run" do it "should succeed and run both" do diff --git a/spec/jasmine/click_button/click_button.js b/spec/jasmine/click_button/click_button.js new file mode 100644 index 0000000..6c2afd0 --- /dev/null +++ b/spec/jasmine/click_button/click_button.js @@ -0,0 +1,5 @@ +function yes() { + $('body').append('