lib/qunited/rake_task.rb in qunited-0.3.1 vs lib/qunited/rake_task.rb in qunited-0.4.0
- old
+ new
@@ -6,25 +6,27 @@
#
# default:
# :qunited
attr_accessor :name
- # Glob pattern to match JavaScript source files (and any dependencies). Note that the
- # order will be indeterminate so if your JavaScript files must be included in a particular
- # order you will have to use source_files=(files_array).
- #
- # If an array of files is set with source_files=(files_array) then this will be ignored.
- attr_accessor :source_files_pattern
+ # <b>DEPRECATED:</b> Please use <tt>source_files=</tt>, which now takes either an array of files
+ # or a glob pattern string.
+ def source_files_pattern=(pattern)
+ warn 'source_files_pattern= is deprecated in QUnited rake task config, use source_files= with a pattern'
+ @source_files = pattern
+ end
# Array of JavaScript source files (and any dependencies). These will be loaded in order
# before loading the QUnit tests.
attr_accessor :source_files
- # Glob pattern to match QUnit test files.
- #
- # If an array of test files is set with test_files=(files) then this will be ignored.
- attr_accessor :test_files_pattern
+ # <b>DEPRECATED:</b> Please use <tt>test_files=</tt>, which now takes either an array of files
+ # or a glob pattern string.
+ def test_files_pattern=(pattern)
+ warn 'test_files_pattern= is deprecated in QUnited rake task config, use test_files= with a pattern'
+ @test_files = pattern
+ end
# Array of QUnit test files.
attr_accessor :test_files
# The driver to use to run the QUnit tests.
@@ -34,19 +36,26 @@
#
# default:
# true
attr_accessor :verbose
+ # Fail rake task when tests fail.
+ #
+ # default:
+ # true
+ attr_accessor :fail_on_test_failure
+
# The port to use if running the server.
#
# default:
# 3040
attr_accessor :server_port
def initialize(*args)
@name = args.shift || :qunited
@verbose = true
+ @fail_on_test_failure = true
@server_port = nil
yield self if block_given?
desc('Run QUnit JavaScript tests') unless ::Rake.application.last_comment
@@ -58,16 +67,23 @@
msg << " with pattern #{source_files_pattern}" if source_files_pattern
puts msg
elsif test_files_to_run.empty?
puts "No QUnit test files matching #{test_files_pattern} could be found"
else
- begin
- puts command if verbose
- success = system(command)
- rescue
+ command = test_command
+ puts command if verbose
+ success = system(command)
+
+ unless success
+ if $?.exitstatus == 10
+ # 10 is our test failure status code
+ fail 'QUnit tests failed' if @fail_on_test_failure
+ else
+ # Other status codes should mean unexpected crashes
+ fail 'Something went wrong when running tests with QUnited'
+ end
end
- raise "#{command} failed" unless success
end
end
end
desc('Run server for QUnit JavaScript tests')
@@ -83,21 +99,26 @@
end
end
private
- def command
+ def test_command
cmd = 'qunited'
cmd << " --driver #{driver}" if driver
cmd << " #{source_files_to_include.join(' ')} -- #{test_files_to_run.join(' ')}"
end
def source_files_to_include
- source_files || pattern_to_filelist(source_files_pattern)
+ files_array source_files
end
def test_files_to_run
- test_files || pattern_to_filelist(test_files_pattern)
+ files_array test_files
+ end
+
+ # Force convert to array of files if glob pattern
+ def files_array(files)
+ files.is_a?(Array) ? files : pattern_to_filelist(files.to_s)
end
def pattern_to_filelist(pattern)
FileList[pattern].map { |f| f.gsub(/"/, '\"').gsub(/'/, "\\\\'") }
end