Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expected exceptions #10

Closed
tfausak opened this Issue Aug 20, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@tfausak
Copy link

tfausak commented Aug 20, 2014

Sometimes you want to show how your code can fail, meaning you want it to raise an exception. Python's doctest supports exceptions: https://docs.python.org/3.4/library/doctest.html#what-about-exceptions.

>>> 1 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
Trying:
    1 / 0
Expecting:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ZeroDivisionError: integer division or modulo by zero
ok

I cannot get a similar example to work using Ruby DocTest.

>> 1 / 0
ZeroDivisionError: divided by 0
    from (irb):1:in `/'
    from (irb):1
    from /usr/bin/irb:12:in `<main>'
1.  ERR  | Default Test
           ZeroDivisionError: divided by 0
             from tmp/example.rb.txt:1
           1 / 0
@weakish

This comment has been minimized.

Copy link

weakish commented Nov 6, 2014

In a verbose approach:

>> begin
 |   1 / 0
 | rescue ZeroDivisionError  
 |   'expected'
 | end  
=> "expected"
@tfausak

This comment has been minimized.

Copy link
Author

tfausak commented Sep 11, 2015

While it is certainly possible to get this behavior with rubydoctest, I decided to make my own gem instead. You can read more about it here: http://taylor.fausak.me/2014/09/23/executable-documentation/

Since this issue hasn't had any movement for a year, I'll just close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.