Add return values for assert and assert_equal#19
Add return values for assert and assert_equal#19britishtea wants to merge 1 commit intodjanowski:masterfrom britishtea:master
Conversation
Both assert and assert_equal used to return nil
|
|
|
My use case is similar. I depend on the return value in a library that makes it convenient to run multiple tests with random input to test if some property holds. Stig.property(String) do |random_string|
assert MyLibrary.takes(random_string)
endAs long as the result of the block is truthy for all generated values, a property is considered held. If the result of the block is falsy, a property is considered not held and an exception is raised. Unfortunately, this happens when I stick a cutest assertion in the block. I prefer to use cutest's assertions for the visual feedback. Depending on a truthy/falsy value also keeps the library test-framework agnostic. Currently, with cutest I'd have to write a wrapper function like below or lose the visual feedback. def assert_property(*args, &block)
Stig.property(args) { |*block_args| assert block.call(block_args) }
end
assert_property(String) do |random_string|
MyLibrary.takes(random_string)
end |
To be consistent with
assert_raise(which returns its exception), makeassertandassert_equalreturn a value more informative thannil.assertwill return the value it has been passed.assert_equalwill returntrue. It can't return a more useful value, because1might be equal to2if#==has been redefined.