Class: QUnited::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/qunited/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# 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

Instance Attribute Details

#driverObject

The driver to use to run the QUnit tests.



42
43
44
# File 'lib/qunited/rake_task.rb', line 42

def driver
  @driver
end

#fail_on_test_failureObject

Fail rake task when tests fail.

default:

true


54
55
56
# File 'lib/qunited/rake_task.rb', line 54

def fail_on_test_failure
  @fail_on_test_failure
end

#fixture_filesObject

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.



39
40
41
# File 'lib/qunited/rake_task.rb', line 39

def fixture_files
  @fixture_files
end

#helper_filesObject

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.



35
36
37
# File 'lib/qunited/rake_task.rb', line 35

def helper_files
  @helper_files
end

#nameObject

Name of task.

default:

:qunited


9
10
11
# File 'lib/qunited/rake_task.rb', line 9

def name
  @name
end

#server_portObject

The port to use if running the server.

default:

3040


60
61
62
# File 'lib/qunited/rake_task.rb', line 60

def server_port
  @server_port
end

#source_filesObject

Array or glob pattern of JavaScript source files (and any dependencies). These will be loaded in order if specified as an array.



20
21
22
# File 'lib/qunited/rake_task.rb', line 20

def source_files
  @source_files
end

#test_filesObject

Array or glob pattern of QUnit test files. These will be loaded in order if specified as an array.



30
31
32
# File 'lib/qunited/rake_task.rb', line 30

def test_files
  @test_files
end

#verboseObject

Use verbose output. If this is true, the task will print the QUnited command to stdout.

default:

true


48
49
50
# File 'lib/qunited/rake_task.rb', line 48

def verbose
  @verbose
end

Instance Method Details

#source_files_pattern=(pattern) ⇒ Object

DEPRECATED: Please use source_files=, which now takes either an array of files or a glob pattern string.



13
14
15
16
# 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

#test_files_pattern=(pattern) ⇒ Object

DEPRECATED: Please use test_files=, which now takes either an array of files or a glob pattern string.



24
25
26
27
# 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