Skip to content

Commit

Permalink
Added Rake task to run tests with PhantomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
karmi committed Aug 13, 2012
1 parent 1f1b2fc commit 3fe4de2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Rakefile
@@ -0,0 +1,39 @@
%w| ansi/core popen4 |.each do |lib|
begin
require lib
rescue LoadError => e
gem_name = lib.split('/').first
puts "[!] Required Rubygem '#{gem_name}' not found, install with:",
" gem install #{gem_name}", ""
exit(1)
end
end

desc "Run tests with phantomjs"
task :test do |t, args|
unless system("which phantomjs > /dev/null 2>&1")
puts ANSI.red("[!] PhantomJS is not installed, aborting... See <http://phantomjs.org>")
exit(1)
end

system "curl -s -X DELETE 'http://localhost:9200/people-test' > /dev/null"

cmd = "phantomjs tests/run-qunit.js '#{File.dirname(__FILE__)}/tests/index.html'"
# puts cmd

result = ''

status = POpen4::popen4(cmd) do |stdout, stderr, stdin, pid|
while line = stdout.gets
if line =~ /Time:/
result = line.chomp
else
puts line
end
end
end

color = status.success? ? :green : :red
puts ['='*80, result, '-'*80].join("\n").ansi( color )
exit(status.exitstatus)
end

0 comments on commit 3fe4de2

Please sign in to comment.