简体   繁体   中英

How to remove desc messages from rspec when using thor?

Now I am using thor in a rails project.

I wrote these codes:

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

The problem is when I run bundle exec rspec , it showed:

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

Why the desc messages been shown here? How to config to remove them?

Haven't tested it, but I'd imagine you could probably patch it out with something like:

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

EDIT: actually it looks like this might be handled a little differently here: https://github.com/erikhuda/thor/blob/master/lib/thor/shell/basic.rb

It looks like you could stub out Thor::Shell::Basic#stdout and #stderr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM