# Testomg: doing def test\_blah or test "blah" do

**URL:** <https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389>\
**Category:** Rails\
**Created:** [July 11, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389 "2010-07-11T16:45:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![firecube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@firecube](https://www.ruby-forum.com/u/firecube)\
**Post date:** [July 11, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389/1 "2010-07-11T16:45:09Z")

</div>

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

1. 

def test\_something\_to\_test

end

and like

1. 

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.

---

<div class="post-metadata">

**Author:** ![firecube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@firecube](https://www.ruby-forum.com/u/firecube)\
**Post date:** [July 12, 2010, 12:07pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389/2 "2010-07-12T12:07:07Z")

</div>

On Jul 11, 3:45 pm, David Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1.

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

---

<div class="post-metadata">

**Author:** ![firecube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@firecube](https://www.ruby-forum.com/u/firecube)\
**Post date:** [July 12, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389/3 "2010-07-12T15:44:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![firecube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@firecube](https://www.ruby-forum.com/u/firecube)\
**Post date:** [July 12, 2010, 4:05pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389/4 "2010-07-12T16:05:25Z")

</div>

Frederick C. wrote:

> On Jul 12, 2:44ï¿½pm, “Daze Z.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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…

---

<div class="post-metadata">

**Author:** ![firecube](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@firecube](https://www.ruby-forum.com/u/firecube)\
**Post date:** [July 12, 2010, 3:51pm UTC](https://www.ruby-forum.com/t/testomg-doing-def-test-blah-or-test-blah-do/191389/5 "2010-07-12T15:51:22Z")

</div>

On Jul 12, 2:44 pm, “Daze Z.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
