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

  • Home
  • SEARCH
  • 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 6806407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:42:24+00:00 2026-05-26T19:42:24+00:00

I have a class with an instance method that runs RSpec using the %x[]

  • 0

I have a class with an instance method that runs RSpec using the %x[] notation:

class TestRunner
  def run_rspec
    # do stuff
    %x[rspec spec -c -f documentation]
    # do more stuff
  end
end

When I do this:

> tr = TestRunner.new
> tr.run_rspec

The documentation (group and example names) does not appear in the console.

To contrast, when I run rspec straight from the command line I get this:

$ rspec spec -c -f documentation

  a group name
    an example
    another example
    ...

I don’t want to do this:

puts %x[rspec spec -c -f documentation

Because then the output all spits out in one huge clump at the very end. I want it to run in “real time,” with each example showing up as each test is run.

Is there a way, with the setup I have, to get RSpec to announce what it’s doing, as it’s doing it (as it does when run normally from the command line)?

  • 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-26T19:42:25+00:00Added an answer on May 26, 2026 at 7:42 pm

    I’ve been advised that system() and the other shell methods can be dangerous to use, so I’ve opted to switch to the even-better approach of using RSpec itself:

    RSpec::Core::Runner.run(['spec', '-c', '-f', 'documentation'])
    

    rather than calling it via shell from my Ruby script.


    Ruby offers several options for running programs from the command line. I was using %x[], the wrong choice for my use case.

    Solution: Use system(), not %x[] — rspec will write to STDOUT in real-time when I call it with system('rspec spec').


    Some background in case it’s helpful to anyone who stumbles upon this question:

    Consider the differences between Ruby’s command-line options:

    • %x[command] accumulates the result of command and returns it, in one chunk.
    • exec('command') will output command as command runs, but will replace whatever process called it — i.e., if you use exec in your Ruby script, your Ruby script won’t finish.
    • system('command') executes command in a subshell, and returns to the calling script.

    This is why system was the choice for my script.

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

Sidebar

Related Questions

If I have for example a class with instance method and variables class Foo
Is it possible in Delphi to have a class method invoke an inherited instance
I have a class Page that creates an instance of DB , which is
I have a class 'Database' that works as a wrapper for ADO.net. For instance,
I have a class (Descendant1) that inherits from a base class (BaseClass). An instance
I have some code that runs within a multithreaded class. Basically i create many
I have a SSIS package that runs on a SQL Server 2005 instance that
I have been looking at a class that has a method that accepts a
I have a class that has two method in it, one calls a class
I have class Books and method select in it. Also there is an instance

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.