From 99c939e6d048c93cd8a7cbd7b7bd4be6a9f67a10 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 28 Jun 2011 11:24:11 -0400 Subject: [PATCH] raise exceptions on rake task failures, hopefully addresses #26 --- lib/jasmine/headless/errors.rb | 3 ++ lib/jasmine/headless/task.rb | 22 ++++++++---- spec/lib/jasmine/headless/task_spec.rb | 48 +++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/lib/jasmine/headless/errors.rb b/lib/jasmine/headless/errors.rb index fa7e603..ef92b8a 100644 --- a/lib/jasmine/headless/errors.rb +++ b/lib/jasmine/headless/errors.rb @@ -5,6 +5,9 @@ module Jasmine "The jasmine-headless-webkit specrunner (jasmine-webkit-specrunner) could not be found! Try reinstalling the gem." end end + + class TestFailure < StandardError; end + class ConsoleLogUsage < StandardError ; end end end diff --git a/lib/jasmine/headless/task.rb b/lib/jasmine/headless/task.rb index 7cc9cae..a727378 100644 --- a/lib/jasmine/headless/task.rb +++ b/lib/jasmine/headless/task.rb @@ -35,13 +35,8 @@ module Jasmine yield self if block_given? desc 'Run Jasmine specs headlessly' - task name do - Jasmine::Headless::Runner.run( - :colors => colors, - :remove_html_file => !@keep_on_error, - :jasmine_config => @jasmine_config - ) - end + task(name) { run_rake_task } + create_rails_compliant_task if defined?(Rails) end @@ -56,6 +51,19 @@ module Jasmine end end end + + def run_rake_task + case Jasmine::Headless::Runner.run( + :colors => colors, + :remove_html_file => !@keep_on_error, + :jasmine_config => @jasmine_config + ) + when 1 + raise Jasmine::Headless::TestFailure + when 2 + raise Jasmine::Headless::ConsoleLogUsage + end + end end end end diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb index 2fedc62..a6dc643 100644 --- a/spec/lib/jasmine/headless/task_spec.rb +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -4,16 +4,16 @@ require 'jasmine/headless/task' require 'mocha' describe Jasmine::Headless::Task do + before do + Jasmine::Headless::Task.any_instance.stubs(:desc) + Jasmine::Headless::Task.any_instance.stubs(:task) + end + after do Object.send(:remove_const, :Rails) if defined?(Rails) end describe 'define task' do - before do - Jasmine::Headless::Task.any_instance.stubs(:desc) - Jasmine::Headless::Task.any_instance.stubs(:task) - end - context 'without Rails' do it 'should not explode when Rails is undefined' do Jasmine::Headless::Task.new('jasmine:headless') @@ -34,5 +34,43 @@ describe Jasmine::Headless::Task do end end end + + describe 'jasmine:headless integration test' do + context 'with successful test' do + let(:test) do + described_class.new do |t| + t.jasmine_config = "spec/jasmine/success/success.yml" + end + end + + it 'should do nothing on success' do + expect { test.send(:run_rake_task) }.to_not raise_error + end + end + + context 'with failing test' do + let(:test) do + described_class.new do |t| + t.jasmine_config = "spec/jasmine/failure/failure.yml" + end + end + + it 'should raise an exception on failure' do + expect { test.send(:run_rake_task) }.to raise_error(Jasmine::Headless::TestFailure) + end + end + + context 'with console.log using test' do + let(:test) do + described_class.new do |t| + t.jasmine_config = "spec/jasmine/console_log/console_log.yml" + end + end + + it 'should raise an exception on console.log usage' do + expect { test.send(:run_rake_task) }.to raise_error(Jasmine::Headless::ConsoleLogUsage) + end + end + end end