Class: QUnited::Rails::TestTask

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

Constant Summary collapse

TMP_DIR_NAME =
'qunited-compiled-js'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TestTask.

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/qunited/rails/test_task.rb', line 51

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 => :environment) do
    internal_task_name = "qunited-rails-#{@name}"
    QUnited::RakeTask.new(internal_task_name) do |t|
      create_tmp_dir

      compiled_source_files = []
      source_paths.each do |path|
        compiled_source_files << compile_and_write_tmp_file(path)
      end

      t.source_files = compiled_source_files
      %w[test_files helper_files fixture_files driver verbose fail_on_test_failure server_port].each do |a|
        t.send("#{a}=", send(a))
      end
    end

    Rake::Task[internal_task_name].invoke
  end
end

Instance Attribute Details

#driverObject

The driver to use to run the QUnit tests.



31
32
33
# File 'lib/qunited/rails/test_task.rb', line 31

def driver
  @driver
end

#fail_on_test_failureObject

Fail rake task when tests fail.

default:

true


43
44
45
# File 'lib/qunited/rails/test_task.rb', line 43

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.



28
29
30
# File 'lib/qunited/rails/test_task.rb', line 28

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.



24
25
26
# File 'lib/qunited/rails/test_task.rb', line 24

def helper_files
  @helper_files
end

#nameObject

Name of task.

default:

:qunited


12
13
14
# File 'lib/qunited/rails/test_task.rb', line 12

def name
  @name
end

#server_portObject

The port to use if running the server.

default:

3040


49
50
51
# File 'lib/qunited/rails/test_task.rb', line 49

def server_port
  @server_port
end

#source_paths=(value) ⇒ Object

Array or strings specifying logical paths of Assets. These will be loaded in order if specified as an array.



16
17
18
# File 'lib/qunited/rails/test_task.rb', line 16

def source_paths=(value)
  @source_paths = value
end

#test_filesObject

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



19
20
21
# File 'lib/qunited/rails/test_task.rb', line 19

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


37
38
39
# File 'lib/qunited/rails/test_task.rb', line 37

def verbose
  @verbose
end