redding / assert

Assertion style testing framework.
https://github.com/redding/assert
MIT License
10 stars 1 forks source link

`with_backtrace` context helper method #133

Closed kellyredding closed 11 years ago

kellyredding commented 11 years ago

This method takes a backtrace and block. It then runs the block and takes any results generated by the block and replaces their backtrace with the given backtrace.

This allows 3rd-party tools to write their own custom assertions and have them abstract the 3rd-party backtraces that any results would have.

An example usage would be:

def assert_some_custom_behavior(*args)
  with_backtrace(caller) do
    # asset some things (generate results)
  end
end

Note: this does not affect error results. These results need to have "pure" backtraces to assist in debugging (error result backtraces are never modified in Assert). This will, however, affect skip and halt-on-fail results: with_backtrace rescues the exceptions raised in those scenarios and sets the exception's backtrace to the given backtrace and then re-raises. This way you get both the halt behavior of the result and the backtrace abstraction of with_exception.

@jcredding this should help with your MR custom assertions. I'm going to head over there and test this in MR. Ready for review.

jcredding commented 11 years ago

@kellyredding - Very nice :boom: This is a handy tool we will need to make use of wherever we do custom assert assertions.