Detect Rspec test failure on after each method

前端 未结 3 1768
既然无缘
既然无缘 2021-01-01 12:44

I am trying to run an RSpec test, and I want to detect if the test failed in the after method. I have something like this right now:

after(:each         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 13:19

    I was looking for how to check if success for all examples in a group in a after(:context) / after(:all) block. Here's what I came up with:

    after(:all) do |example_group|
      all_groups = example_group.class.descendants
      failed_examples = all_groups.map(&:examples).flatten.select(&:exception)
    
      if failed_examples.empty?
        # runs only if there are no failures
        do('something')
      end
    end
    

提交回复
热议问题