2011-06-16 23:38:45 +00:00
|
|
|
require 'jasmine/headless/runner'
|
|
|
|
|
2011-06-21 10:49:00 +00:00
|
|
|
module Digest
|
|
|
|
class JasmineTest
|
|
|
|
def self.file(file)
|
|
|
|
new
|
|
|
|
end
|
|
|
|
|
|
|
|
def file(file)
|
|
|
|
self
|
|
|
|
end
|
2011-06-28 15:06:36 +00:00
|
|
|
|
2011-06-21 10:49:00 +00:00
|
|
|
def hexdigest
|
|
|
|
'test'
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(prefix)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 11:47:42 +00:00
|
|
|
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
|
|
|
|
2011-05-17 11:47:42 +00:00
|
|
|
attr_accessor :colors, :keep_on_error, :jasmine_config
|
|
|
|
|
|
|
|
def initialize(name = 'jasmine:headless')
|
|
|
|
@colors = false
|
|
|
|
@keep_on_error = false
|
|
|
|
@jasmine_config = nil
|
|
|
|
|
|
|
|
yield self if block_given?
|
|
|
|
|
|
|
|
desc 'Run Jasmine specs headlessly'
|
2011-06-28 15:24:11 +00:00
|
|
|
task(name) { run_rake_task }
|
|
|
|
|
2011-06-28 15:06:36 +00:00
|
|
|
create_rails_compliant_task if defined?(Rails)
|
2011-06-28 08:25:32 +00:00
|
|
|
end
|
2011-06-28 15:06:36 +00:00
|
|
|
|
2011-06-28 08:25:32 +00:00
|
|
|
private
|
|
|
|
def create_rails_compliant_task
|
2011-07-19 14:29:25 +00:00
|
|
|
if Rails.respond_to?(:version) && Rails.version >= "3.1.0"
|
2011-06-28 15:06:36 +00:00
|
|
|
desc 'Force generate static assets without an MD5 hash, all assets end with -test.<ext>'
|
|
|
|
task 'assets:precompile:for_testing' => :environment do
|
|
|
|
Rails.application.assets.digest_class = Digest::JasmineTest
|
2011-06-28 08:25:32 +00:00
|
|
|
|
2011-06-28 15:06:36 +00:00
|
|
|
Rake::Task['assets:precompile'].invoke
|
2011-06-21 10:49:00 +00:00
|
|
|
end
|
2011-06-28 15:06:36 +00:00
|
|
|
end
|
2011-05-17 11:47:42 +00:00
|
|
|
end
|
2011-06-28 15:24:11 +00:00
|
|
|
|
|
|
|
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
|
2011-05-17 11:47:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|