Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:16:18+00:00 2026-05-26T13:16:18+00:00

I have a few pure-JavaScript, client-side tests using PhantomJS. These I’d like to integrate

  • 0

I have a few pure-JavaScript, client-side tests using PhantomJS. These I’d like to integrate with rake test.

Currently I use this:

namespace :test do

  task :client do
    basedir = Rails.root.join("test", "client")
    sh "cd #{basedir} && phantomjs lib/run-qunit.js index.html"
  end

end

task :test => "test:client"

However, this integration is far from perfect; if one of these tests fails, rake aborts. Also, in contrast to :units, :functionals and :integration, there is no summary of the issues at the end (e.g. “6 tests, 21 assertions, 1 failures, 0 errors”).

I could extract that data easily enough, but how do I tell Rake to add it to the total test tally?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:16:19+00:00Added an answer on May 26, 2026 at 1:16 pm

    You are calling via sh a shell command. Ruby does not know, that it is a test.
    In addition sh seems to stop, if a failure occurs.

    You have to do two things: Catch the error and check the result of your call.

    An example:

    require 'rake'
    $summary = Hash.new(0)
    
    def mytest(name, cmd)
      $summary['test'] += 1
      sh cmd do |ok, res|
        if ok 
          $summary['ok'] += 1
        else
          $summary['failure'] += 1
          puts "#{cmd } failed"
        end
      end
    end
    namespace :test do
      task :one do |tsk|
         mytest(tsk.name, "dir")
      end
      task :two do |tsk|
         mytest(tsk.name, "undefined_cmd")
      end
      task :summary do
        p $summary
      end
    end
    
    task :test => "test:one"
    task :test => "test:two"
    task :test => "test:summary"
    

    shis called with a block to catch failures. Inside the block, I analyse the result (true for ok, false if the script stops with an error. The result is added to a summary hash.

    For your use, you may adapt the code and split the code into two files: All test in one file. And the rake file get a Rake::TestTast.

    Your test file may look like this:

    gem 'test-unit'
    require 'test/unit'
    
    class MyTest < Test::Unit::TestCase
      def test_one
        assert_nothing_raised{
          basedir = Rails.root.join("test", "client")        
          res = system("cd #{basedir} && phantomjs lib/run-qunit.js index.html")
          assert_true(res)
        }
    
      end
      def test_two
        assert_nothing_raised{
          res = `dir` #Test with windows
          assert_match(/C:/, res) #We are in c: 
        }
      end
    end
    

    This works only, if your test finish with a exit code. Perhaps you can use `` instead and get the output of your test for a detailed analyze.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pure Winapi application that needs a few new features. One of
I have few different applications among which I'd like to share a C# enum.
We have few components like libraries dlls When initially created I ran the following
I have a server-generated html like: <ul> <li><!-- few nested elements that form a
I have seen a few of these jquery things going on, and just wondered
I have few pairs of button & check box like on my pages (the
I have few asynchronous tasks running and I need to wait until at least
I have few question in this regard When you create an internet page, does
I have few nested DIVs at page. I want to add event only for
I have few small basic problems : How to format : int i =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.