raise exceptions on rake task failures, hopefully addresses #26

This commit is contained in:
John Bintz 2011-06-28 11:24:11 -04:00
parent 7316f77367
commit 99c939e6d0
3 changed files with 61 additions and 12 deletions

View File

@ -5,6 +5,9 @@ module Jasmine
"The jasmine-headless-webkit specrunner (jasmine-webkit-specrunner) could not be found! Try reinstalling the gem." "The jasmine-headless-webkit specrunner (jasmine-webkit-specrunner) could not be found! Try reinstalling the gem."
end end
end end
class TestFailure < StandardError; end
class ConsoleLogUsage < StandardError ; end
end end
end end

View File

@ -35,13 +35,8 @@ module Jasmine
yield self if block_given? yield self if block_given?
desc 'Run Jasmine specs headlessly' desc 'Run Jasmine specs headlessly'
task name do task(name) { run_rake_task }
Jasmine::Headless::Runner.run(
:colors => colors,
:remove_html_file => !@keep_on_error,
:jasmine_config => @jasmine_config
)
end
create_rails_compliant_task if defined?(Rails) create_rails_compliant_task if defined?(Rails)
end end
@ -56,6 +51,19 @@ module Jasmine
end end
end 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 end
end end

View File

@ -4,16 +4,16 @@ require 'jasmine/headless/task'
require 'mocha' require 'mocha'
describe Jasmine::Headless::Task do describe Jasmine::Headless::Task do
after do
Object.send(:remove_const, :Rails) if defined?(Rails)
end
describe 'define task' do
before do before do
Jasmine::Headless::Task.any_instance.stubs(:desc) Jasmine::Headless::Task.any_instance.stubs(:desc)
Jasmine::Headless::Task.any_instance.stubs(:task) Jasmine::Headless::Task.any_instance.stubs(:task)
end end
after do
Object.send(:remove_const, :Rails) if defined?(Rails)
end
describe 'define task' do
context 'without Rails' do context 'without Rails' do
it 'should not explode when Rails is undefined' do it 'should not explode when Rails is undefined' do
Jasmine::Headless::Task.new('jasmine:headless') Jasmine::Headless::Task.new('jasmine:headless')
@ -34,5 +34,43 @@ describe Jasmine::Headless::Task do
end end
end 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 end