Search code examples
rubytestingrspecthor

disable warnings when testing thor CLI


I have a CLI app that uses the thor gem.

My tests pass, but because I am testing the API directory, I get a lot of warnings:

All examples were filtered out; ignoring {:focus=>true}
.......
[WARNING] Attempted to create command "__email_dir?_without_any_instance__" without usage or description. 
Call desc if you want this method to be available as command or declare it inside a no_commands{} block. 
Invoked from "/Users/julieng/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-mocks-3.1.2/lib/rspec/mocks/any_instance/recorder.rb:211:in `alias_method'".

I have ENV['RACK_ENV']='test' in my spec_helper.rb file, which according to a SO search, was supposed to help.

I found some other SO threads (example), but I am not testing any input, just calling API methods directly.

This is just annoying. Any ideas on how to resolve it?

Thanks


Solution

  • It's a bit of a shotgun approach, but when I really want to suppress message cruft from the command line and keep the test output clean, in my tests I'll just stub out $stdouts output stream eg:

    describe CLI do
      before do
        allow($stdout).to receive(:write)
      end
    
      # your tests here ...
    end