簡體   English   中英

使用thor時如何從rspec中刪除desc消息?

[英]How to remove desc messages from rspec when using thor?

現在,我在Rails項目中使用thor

我寫了這些代碼:

lib /任務/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消息? 如何配置刪除它們?

還沒有測試過,但我想您可能會用類似以下的方法來修補它:

module Thor
  def puts(*args, &block)
    # do nothing
  end
end

編輯:實際上看起來這可能在這里有所不同: https//github.com/erikhuda/thor/blob/master/lib/thor/shell/basic.rb

看來您可以對Thor::Shell::Basic#stdout#stderr

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM