Detect Rspec test failure on after each method

前端 未结 3 1766
既然无缘
既然无缘 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:09

    EDIT: this answer is only valid for RSpec 2. for RSpec 3 see geekazoid's answer.

    The after each block runs in the context of class which exposes example and you can detect failures by checking the exception method on example thusly:

    after(:each) do
      if example.exception != nil
        # Failure only code goes here
      end
    end
    

提交回复
热议问题