Skip to content

Commit

Permalink
Merge pull request #4 from emancu/3-use_temporary_variables
Browse files Browse the repository at this point in the history
Use temporary variables
  • Loading branch information
emancu committed Apr 7, 2016
2 parents 63f191e + 9158dd3 commit cf4e97e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/crotest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Crotest

def self.increment(key : Symbol)
@@counters[key] += 1
print '.'
end

def self.report(result : Test)
Expand Down
9 changes: 2 additions & 7 deletions src/crotest/assertions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Crotest::Assertions
raise Crotest::AssertionFailed.new(%msg, {{file}}, {{line}})
end

success
Crotest.increment(:assertions)
end

# Assert that expression is falsey
Expand All @@ -32,7 +32,7 @@ module Crotest::Assertions
begin
{{yield}}
rescue %exception : {{expected}}
success
Crotest.increment(:assertions)
rescue %exception
%result = %exception.is_a?({{expected}})

Expand All @@ -43,9 +43,4 @@ module Crotest::Assertions
raise Crotest::AssertionFailed.new(%msg, {{file}}, {{line}})
end
end

private def success
Crotest.increment(:assertions)
print "."
end
end
12 changes: 6 additions & 6 deletions src/crotest/dsl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ module Crotest::DSL

begin
{{ yield }}
rescue exception : Crotest::AssertionFailed
result = Crotest::FailedTest.new {{name}}, {{file}}, {{line}}, exception
rescue exception : Exception
result = Crotest::ErroredTest.new {{name}}, {{file}}, {{line}}, exception
rescue %exception : Crotest::AssertionFailed
%result = Crotest::FailedTest.new {{name}}, {{file}}, {{line}}, %exception
rescue %exception : Exception
%result = Crotest::ErroredTest.new {{name}}, {{file}}, {{line}}, %exception
ensure
result ||= Crotest::PassedTest.new {{name}}, {{file}}, {{line}}
%result ||= Crotest::PassedTest.new {{name}}, {{file}}, {{line}}

Crotest.report result
Crotest.report %result
end

Crotest::ContextPlan.teardown
Expand Down

0 comments on commit cf4e97e

Please sign in to comment.