如果没有断言,是否有办法使RSpec失败?

时间:2018-09-11 20:36:23

标签: rspec

Minitest有proveit!

RSpec是否具有类似的要求断言的方式?

2 个答案:

答案 0 :(得分:1)

这是我的看法

, 'DELETE');

答案 1 :(得分:0)

您可以为此配置RSpec,请检查以下内容:

https://github.com/rspec/rspec-core/issues/404#issuecomment-11431199http://blog.sorah.jp/2012/12/17/rspec-warn-for-no-expectations

基本上,您需要设置after挂钩并检查是否有预期运行的元数据: (以防万一,如果网址不正确,则复制代码)

RSpec.configure do |config|
  config.after(:each) do
    result = self.example.metadata[:execution_result]
    has_mock_expectations = RSpec::Mocks.space.instance_eval{receivers}.empty?
    if !result[:exception] && !result[:pending_message] && !RSpec::Matchers.last_should && hasnt_mock_expectations
      $stderr.puts "[WARN] No expectations found in example at #{self.example.location}: Maybe you forgot to write `should` in the example?"
    end
  end
end