Class: QunitCliRunner::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/qunit-cli-runner/task.rb

Instance Method Summary collapse

Constructor Details

#initialize(name_or_opts = nil, opts = nil) ⇒ Task

Returns a new instance of Task.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/qunit-cli-runner/task.rb', line 5

def initialize(name_or_opts=nil, opts=nil)
  if name_or_opts.is_a?(Hash)
    opts = name_or_opts
  else
    name = name_or_opts
  end

  name ||= "test"
  opts ||= {}
  opts[:path] ||= File.join(Dir.pwd, "tests", "index.html")
  opts[:test_args] ||= ['']

  Rake::Task.define_task(name) do
    success = true

    puts "Running Tests..."

    opts[:test_args].each do |args|
      puts args
      cmd = "phantomjs \"#{QunitCliRunner.path}\" \"file://localhost#{opts[:path]}?#{args}\""
      system(cmd)

      # A bit of a hack until we can figure this out on Travis
      tries = 0
      while tries < 3 && $?.exitstatus === 124
        tries += 1
        puts "\nTimed Out. Trying again...\n"
        system(cmd)
      end

      success &&= $?.success?
    end

    if success
      puts "\nTests Passed".green
    else
      puts "\nTests Failed".red
      exit(1)
    end
  end
end