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

Add return values for assert and assert_equal #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/cutest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ def test(name = nil, &block)
def assert(value)
flunk("expression returned #{value.inspect}") unless value
success

value
end

# Assert that two values are equal.
def assert_equal(value, other)
flunk("#{value.inspect} != #{other.inspect}") unless value == other
success

true
end

# Assert that the block doesn't raise the expected exception.
Expand Down
4 changes: 4 additions & 0 deletions test/assert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
assert true
end

test "returns its value" do
assert_equal assert(:value), :value
end

test "raises if the assertion fails" do
assert_raise(Cutest::AssertionFailed) do
assert false
Expand Down
4 changes: 4 additions & 0 deletions test/assert_equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
assert_equal 1, 1
end

test "returns true" do
assert_equal assert_equal(1, 1), true
end

test "raises if the assertion fails" do
assert_raise(Cutest::AssertionFailed) do
assert_equal 1, 2
Expand Down