Testomg: doing def test_blah or test "blah" do

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

1.
def test_something_to_test

end

and like

2.
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.

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

1.
def test_something_to_test

end

and like

2.
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?

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 Cheung 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 Cheung 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?

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.

Frederick Cheung wrote: