Skip to content

Instantly share code, notes, and snippets.

@foysavas
Forked from mattknox/inline_test
Created March 18, 2010 21:13

Revisions

  1. foysavas revised this gist Mar 18, 2010. 3 changed files with 22 additions and 26 deletions.
    10 changes: 10 additions & 0 deletions console
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    > 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
    26 changes: 0 additions & 26 deletions inline_test
    Original file line number Diff line number Diff line change
    @@ -1,26 +0,0 @@
    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
    12 changes: 12 additions & 0 deletions math_functions.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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
  2. @mattknox mattknox created this gist Mar 18, 2010.
    26 changes: 26 additions & 0 deletions inline_test
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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