在测试thor CLI时禁用警告

时间:2014-10-13 08:55:48

标签: ruby testing rspec thor

我有一个使用thor gem的CLI应用程序。

我的测试通过,但因为我正在测试API目录,所以我收到了很多警告:

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'".

我的ENV['RACK_ENV']='test'文件中有spec_helper.rb,根据SO搜索,该文件应该有帮助。

我找到了其他一些SO线程(example),但我没有测试任何输入,只是直接调用API方法。

这很烦人。关于如何解决它的任何想法?

由于

2 个答案:

答案 0 :(得分:2)

它有点像猎枪的方法,但是当我真的想要从命令行压制消息并保持测试输出干净时,在我的测试中我只是存根$stdout的输出流,例如:

describe CLI do
  before do
    allow($stdout).to receive(:write)
  end

  # your tests here ...
end

答案 1 :(得分:2)

你可以采用比保罗的压路机式方法更有针对性的方法:

def mean_absolute_percentage_error(y_true, y_pred): 
    y_true, y_pred = np.array(y_true), np.array(y_pred)
    return np.mean(np.abs((y_true - y_pred) / y_true)) * 100

neg_MAPE = make_scorer(mean_absolute_percentage_error, greater_is_better=False)