首页 > 解决方案 > 如果没有断言,有没有办法让 RSpec 失败?

问题描述

Minitest 有proveit!

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

标签: rspec

解决方案


这是我的看法:

RSpec.configure do |config|
  config.include(Module.new do
                   attr_writer :expectation_set_count

                   def expectation_set_count
                     @expectation_set_count ||= 0
                   end

                   def expect(*)
                     self.expectation_set_count += 1

                     super
                   end
                 end)

  config.after do
    expect(expectation_set_count).to be > 0
  end
end

推荐阅读