-
-
Save foysavas/336903 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ruby -rmath_functions.rb -e "puts MathFunctions.factorial(2)" | |
2 | |
> ruby --test -rmath_functions.rb | |
. | |
Finished in 1.000706 seconds. | |
1 tests, 2 assertions, 0 failures, 0 errors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MathFunctions | |
def self.factorial(n) | |
(1..n).inject(1) { |acc, x| acc * x} | |
end | |
end | |
=begin :unittest | |
assert MathFunctions.factorial(6) == 720 | |
assert MathFunctions.factorial(5) == 120 | |
=end |
FYI, I have restructured stuff and started writing a simple gem and added some examples using rspec.
Not sure how this will end up. Here is the repo http://github.com/jeroenvandijk/inline_tests
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very Interesting.
I was thinking about inline tests with the following goals in mind:
So I was thinking to add the test between the normal documentation for a method/module/class. I have currently focused on methods only.
The solution I have come up with is based on the Module#method_added hook method. I need to work it out further to give you a good example, but here is some code I extracted from the code I'm working on http://gist.github.com/388532#file_inline_test.feature . This doesn't work, but I hope it gives you an idea. I do have something simple (like the feature example) working locally.
What do you think of this approach?