Skip to content
Browse files

raise exceptions on rake task failures, hopefully addresses #26

  • Loading branch information...
1 parent 7316f77 commit 99c939e6d048c93cd8a7cbd7b7bd4be6a9f67a10 @johnbintz johnbintz committed Jun 28, 2011
Showing with 61 additions and 12 deletions.
  1. +3 −0 lib/jasmine/headless/errors.rb
  2. +15 −7 lib/jasmine/headless/task.rb
  3. +43 −5 spec/lib/jasmine/headless/task_spec.rb
View
3 lib/jasmine/headless/errors.rb
@@ -5,6 +5,9 @@ def message
"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
View
22 lib/jasmine/headless/task.rb
@@ -35,13 +35,8 @@ def initialize(name = 'jasmine:headless')
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 @@ def create_rails_compliant_task
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
View
48 spec/lib/jasmine/headless/task_spec.rb
@@ -4,16 +4,16 @@
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 @@ def self.version
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

0 comments on commit 99c939e

Please sign in to comment.
Something went wrong with that request. Please try again.