Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用thor时如何从rspec中删除desc消息?_Ruby On Rails_Ruby_Testing_Rspec_Thor - Fatal编程技术网

Ruby on rails 使用thor时如何从rspec中删除desc消息?

Ruby on rails 使用thor时如何从rspec中删除desc消息?,ruby-on-rails,ruby,testing,rspec,thor,Ruby On Rails,Ruby,Testing,Rspec,Thor,现在我正在一个rails项目中使用 我写了这些代码: lib/tasks/my_task.rb require 'thor' module Tasks class MyTask < Thor desc 'My Batch', 'This is my awesome batch' option :date def execute(type) # do_something end end end Tasks::MyTask.start(A

现在我正在一个rails项目中使用

我写了这些代码:

lib/tasks/my_task.rb

require 'thor'

module Tasks
  class MyTask < Thor
    desc 'My Batch', 'This is my awesome batch'
    option :date
    def execute(type)
      # do_something
    end
  end
end

Tasks::MyTask.start(ARGV)
问题是,当我运行bundle exec rspec时,它显示:

Run options: exclude {:heavy=>true}
..................................................................................................................................................................................................****************************...................................................
........................................................************.......................................................................................................................................................................................................******
Commands:
  rspec help [COMMAND]  # Describe available commands or one specific command
  rspec My Batch          # This is my awesome batch
.................................................................................................................................................................................................................................................................................

为什么在这里显示desc消息?如何配置以删除它们?

尚未对其进行测试,但我想您可能可以通过以下方式进行修补:

module Thor
  def puts(*args, &block)
    # do nothing
  end
end
编辑:实际上,这里的处理方式可能有点不同:


看起来您可以删除
Thor::Shell::Basic#stdout
#stderr

这就是
Thor
的工作原理,不清楚您为什么要启动
Thor
CLI并期望它不会按其工作方式工作。如果您不希望显示描述,请不要定义描述。这不是强制性的。@WandMaker,因为在我的项目中,我应该手动运行批处理并使用一些选项。@mudasobwa,如果我不使用它。我的考试不会过去的,谢谢。你的意思是我应该重写Thor模块吗?在你的库中用猴子拼凑出一些方法进行测试并不是不寻常的。它为代码添加了依赖项,但我发现能够测试功能通常是值得的
module Thor
  def puts(*args, &block)
    # do nothing
  end
end