Testomg: doing def test_blah or test "blah" do

Hey, I’m wondering about the distinction between writing test methods
like

def test_something_to_test

end

and like

test “something to test” do

end

It seems like there’s no difference. I did notice, however, that #2
can’t be done in a class that extends Test::Unit::TestCase, while it can
be done in one that extends ActionController::TestCase. I also noticed
that #1 works for classes that extend either.

So which should I use? What is the difference?

Thanks in advance.

On Jul 11, 3:45 pm, David Z. [email protected] wrote:

test “…” do

end

is added by Active Support (as part of ActiveSupport::TestCase (which
ActionController::TestCase inherits from)) which is why you can’t use
it in a Test::Unit::TestCase subclass.

It’s really just a stylistic difference. One of the few differences
I’m aware of is that Active Support’s test “…” allows you not to
provide a method body (and test runs will then tell you about that)
and it will raise an exception if you try to create two tests with the
same name (whereas when just defining instance methods the 2nd
definition would overwrite the first

Fred

Frederick C. wrote:

…One of the few differences
I’m aware of is that Active Support’s test “…” allows you not to
provide a method body (and test runs will then tell you about that)
and it will raise an exception if you try to create two tests with the
same name (whereas when just defining instance methods the 2nd
definition would overwrite the first

Fred

Thanks, Fred.
But what’s the advantage of not providing a method body?

And for your second point (“rais[ing] and exception”): so if I have a
class that inherits from ActiveSupport::TestCase, creating 2 methods
with identical names will cause an error, while if I have a class that
inherits from Test::Unit::TestCase, creating 2 methods with identical
names will NOT cause an error but instead result in the use of the 2nd
definition over the 1st?

Just making sure I understand…thanks again!

Frederick C. wrote:

On Jul 12, 2:44�pm, “Daze Z.” [email protected] wrote:

Thanks, Fred.
But what’s the advantage of not providing a method body?

I think it’s just a way of spelling out what tests you want to write
(and be reminded that they’re still unwritten)

Oh, I see. But couldn’t you not provide a method body for a method in
any class? So you could also do it in one that extends
Test::Unit::TestCase…couldn’t you? How is it “[o]ne of the few
differences”?

thanks again! this site’s pretty good…

On Jul 12, 2:44 pm, “Daze Z.” [email protected] wrote:

Thanks, Fred.
But what’s the advantage of not providing a method body?

I think it’s just a way of spelling out what tests you want to write
(and be reminded that they’re still unwritten)

And for your second point (“rais[ing] and exception”): so if I have a
class that inherits from ActiveSupport::TestCase, creating 2 methods
with identical names will cause an error, while if I have a class that
inherits from Test::Unit::TestCase, creating 2 methods with identical
names will NOT cause an error but instead result in the use of the 2nd
definition over the 1st?

Yup.