【问题标题】:Invoking guard from Rake task suppresses the output从 Rake 任务调用警卫会抑制输出
【发布时间】:2014-12-17 18:56:54
【问题描述】:

我正在尝试将调用测试的命令放置在 Rakefile 中,如下所示:

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

虽然命令:bundle exec guard --clear 否则运行完美;通过 Rake 任务调用测试输出时,它似乎被抑制了。仅输出运行规范或启动 Guard 等通知。

注意:我知道测试确实有效,因为我有另一个通过 tmux 窗格颜色的通知系统。

我认为,我构建 Rake 任务的方式有问题吗?有什么想法吗?

【问题讨论】:

    标签: ruby command-line rake guard


    【解决方案1】:

    是的,%x 会等到命令完成后再打印任何输出。

    例子:

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

    (在完成之前不会显示任何输出 - 然后它会立即显示所有内容。)

    示例 2:

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

    (直到 100 秒过去后才会显示任何内容)。

    你想要的是:

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

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

    【讨论】:

    • 你的意思是说这会在命令完成之前一直打印输出吗?很抱歉,我真的不记得我现在用哪个项目来测试它了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多