测试 RSpec 3.3 发布:支持只执行失败的用例

greatghoul · June 14, 2015 · Last by kgen replied at June 14, 2015 · 2263 hits

http://rspec.info/blog/2015/06/rspec-3-3-has-been-released/

有个比较有用的更新,可以选择只执行失败的用例了。

需要配置一个记录用例执行结果的文件位置(最好加入 .gitignore)

RSpec.configure do |c|
  c.example_status_persistence_file_path = "./spec/examples.txt"
end

然后就可以用下面的命令来只执行失败的用例了,很方便的样子

rspec --only-failures
rspec --next-failure

之前,我一般都是指定只执行失败用例的文件的,不过有加这样的配置,在碰到第一个错误时就停止跑后面的测试。

if config.files_to_run.one?
    config.default_formatter = 'doc'
    config.fail_fast = true
  end

其实用 guard 也不错奥

虽然第三方工具可以实现:只执行失败的用例,如果全部通过,就把所有用例都执行一遍。 不过,RSpec 原生支持了,那自然最好不过了!

You need to Sign in before reply, if you don't have an account, please Sign up first.