Question

Is it possible to check the result of a Ruby Test/Unit in the teardown method?

I am using Ruby with Test/Unit, WATIR and Webdriver to test a web application and would like to grab a screenshot in the teardown method if the test has failed.

Was it helpful?

Solution

How about changing assert_equal (or whatever assertion you're using) instead?

require 'test/unit'

class Test::Unit::TestCase
  def assert_equal(expected, got, msg)
    begin
      super(expected, got, msg)
    rescue
      p "caught ya!" # make screenshot here
      raise
    end
  end
end

class DemoTest < Test::Unit::TestCase

  def test_fail
    assert_equal(1, 0, 'ups')
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top