Jikku Jose
Jikku Jose

Reputation: 18804

Invoking guard from Rake task suppresses the output

I am trying to place the command to invoke tests inside a Rakefile like so:

desc 'Start tests'
task :test do
  %x{ bundle exec guard --clear }
end

Though the command: bundle exec guard --clear runs perfectly otherwise; test output seems to be suppressed when invoked it through the Rake task. Only notifications such as running spec or starting Guard is being outputted.

Note: I know the tests are indeed working as I have another notification system through tmux pane colours.

I think, something is wrong with the way I am building the Rake tasks? Any ideas?

Upvotes: 0

Views: 266

Answers (1)

Cezary Baginski
Cezary Baginski

Reputation: 2105

Yes, the %x waits until the command finishes before printing any output.

Example:

puts %x{ sleep 1; echo "hello"; sleep 2; echo "world"; }

(This will not show any output until it finishes - then it shows everything at once.)

Example 2:

puts %x{ echo "hello"; sleep 100; }

(This will not show anything until 100 seconds have passed).

What you want is:

Kernel.system("bundle exec guard --clear")

or

Kernel.system(%w(bundle exec guard --clear))

Upvotes: 1

Related Questions