jasmine-headless-webkit/lib/jasmine/headless/task.rb

40 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

module Jasmine
module Headless
class Task
2011-06-18 16:43:22 +00:00
include Rake::DSL if defined?(Rake::DSL)
2011-06-16 21:34:00 +00:00
2012-07-28 11:46:22 +00:00
attr_accessor :colors, :keep_on_error, :jasmine_config, :error_on_console_log
def initialize(name = 'jasmine:headless')
@colors = false
@keep_on_error = false
2012-07-28 11:46:22 +00:00
@error_on_console_log = true
@jasmine_config = nil
yield self if block_given?
desc 'Run Jasmine specs headlessly'
task(name) { run_rake_task }
end
private
def run_rake_task
2012-07-28 11:39:31 +00:00
result = Jasmine::Headless::Runner.run(
:colors => colors,
:remove_html_file => !@keep_on_error,
:jasmine_config => @jasmine_config
)
case result
when 1
raise Jasmine::Headless::TestFailure
when 2
2012-07-28 11:46:22 +00:00
raise Jasmine::Headless::ConsoleLogUsage if @error_on_console_log
2012-07-28 11:39:31 +00:00
else
2012-07-28 11:46:22 +00:00
p "Unexpected Jasmine::Headless error code #{result}. If 127, check native extensions have been compiled."
2012-07-28 11:39:31 +00:00
raise Jasmine::Headless::TestFailure
end
end
end
end
end