Ruby on rails 使用thor时如何从rspec中删除desc消息?
现在我正在一个rails项目中使用 我写了这些代码: lib/tasks/my_task.rbRuby 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
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