【发布时间】:2015-09-02 09:01:56
【问题描述】:
现在我在 Rails 项目中使用thor。
我写了这些代码:
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)
spec/lib/tasks/my_task_spec.rb
require 'spec_helper'
describe 'Test my task' do
context 'With date option' do
before do
@option = { date: '20150903' }
end
it 'Can insert to db' do
expect do
Tasks::MyTask.new.invoke(:execute, ['commit'], @option)
end.to change(ProductTable, :count).by(1)
end
end
end
问题是当我运行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 消息?如何配置删除它们?
【问题讨论】:
-
这就是
Thor的工作方式,目前尚不清楚您为什么要启动ThorCLI 并期望它不能按其工作方式工作 -
如果您不想显示描述,请不要定义描述。这不是强制性的。
-
@WandMaker 因为在我的项目中,我应该手动运行批处理并使用一些选项。
-
@mudasobwa 如果我不使用它。我的测试不会通过。
标签: ruby-on-rails ruby testing rspec thor