3

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

Community
  • 1
  • 1
julie-ng
  • 500
  • 6
  • 11

2 Answers2

3

You can get a slightly more targeted approach than Paul's steamroller-style approach with something like this:

describe MyCLI do
  before do
    class Foo < StringIO
      def puts s 
        super unless s.start_with?('[WARNING] Attempted to create command')
      end
    end
    $stdout = Foo.new
  end

  after do
    $stdout = STDOUT
  end

  # your tests here...
end
jayhendren
  • 4,286
  • 2
  • 35
  • 59
2

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
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
  • 1
    Thank you, that's worked beautifully. I'm also only applying to the CLI specs as per your example. Cheers! – julie-ng Oct 19 '14 at 09:38