class QUnited::RakeTask
Attributes
The driver to use to run the QUnit tests.
Fail rake task when tests fail.
default:
true
Array or glob pattern of fixture files. These are included under the qunit-fixture element on the test page. These will be included in order if specified as an array.
Array or glob pattern of test helper files. These include extra libraries for mocks or other test tools. These are loaded after source files and before test files. These will be loaded in order if specified as an array.
Name of task.
default:
:qunited
The port to use if running the server.
default:
3040
Array or glob pattern of JavaScript source files (and any dependencies). These will be loaded in order if specified as an array.
Array or glob pattern of QUnit test files. These will be loaded in order if specified as an array.
Use verbose output. If this is true, the task will print the QUnited
command to stdout.
default:
true
Public Class Methods
# File lib/qunited/rake_task.rb, line 62 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 task name do RakeFileUtils.send(:verbose, verbose) do if source_files_to_include.empty? msg = if source_files.is_a? String "No JavaScript source files match the pattern '#{source_files}'" else 'No JavaScript source files specified' end fail msg elsif test_files_to_run.empty? msg = if test_files.is_a? String "No QUnit test files match the pattern '#{test_files}'" else 'No QUnit test files specified' end fail msg else 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 end end end desc('Run server for QUnit JavaScript tests') task (name.to_s + ':server') do require 'qunited/server' server_options = { :source_files => source_and_helper_files, :test_files => test_files_to_run, :fixture_files => fixture_files_to_include, :verbose => verbose } server_options[:port] = @server_port if @server_port ::QUnited::Server.new(server_options).start end end
Public Instance Methods
DEPRECATED: Please use source_files=
, which now takes either an array of files or a glob pattern string.
# File lib/qunited/rake_task.rb, line 13 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
DEPRECATED: Please use test_files=
, which now takes either an array of files or a glob pattern string.
# File lib/qunited/rake_task.rb, line 24 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
Private Instance Methods
Force convert to array of files if glob pattern
# File lib/qunited/rake_task.rb, line 151 def files_array(files) return [] unless files files.is_a?(Array) ? files : pattern_to_filelist(files.to_s) end
# File lib/qunited/rake_task.rb, line 138 def fixture_files_to_include files_array fixture_files end
# File lib/qunited/rake_task.rb, line 134 def helper_files_to_include files_array helper_files end
# File lib/qunited/rake_task.rb, line 156 def pattern_to_filelist(pattern) FileList[pattern].map { |f| f.gsub(/"/, '\"').gsub(/'/, "\\\\'") } end
# File lib/qunited/rake_task.rb, line 146 def source_and_helper_files source_files_to_include + helper_files_to_include end
# File lib/qunited/rake_task.rb, line 130 def source_files_to_include files_array source_files end
# File lib/qunited/rake_task.rb, line 123 def test_command cmd = 'qunited' cmd << " --driver #{driver}" if driver cmd << " --fixtures #{fixture_files_to_include.join(',')}" if fixture_files cmd << " #{source_and_helper_files.join(' ')} -- #{test_files_to_run.join(' ')}" end
# File lib/qunited/rake_task.rb, line 142 def test_files_to_run files_array test_files end