Skip to content

Instantly share code, notes, and snippets.

@mattknox
Created March 18, 2010 18:16
Show Gist options
  • Save mattknox/336665 to your computer and use it in GitHub Desktop.
Save mattknox/336665 to your computer and use it in GitHub Desktop.
module MathFunctions
include InlineTest
def factorial(n)
(1..n).inject(1) { |acc, x| acc * x}
end
unit_test do
assert factorial(6) == 720
assert factorial(5) == 120
end
end
module InlineTest
def env_is_testy?
true
end
if env_is_testy?
def unit_test(name, &block)
block[]
end
else
def unit_test(*args, &block)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment