# Testing

**URL:** <https://www.ruby-forum.com/t/testing/175474>\
**Category:** Rails\
**Created:** [September 14, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/testing/175474 "2009-09-14T14:06:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/testing/175474/1 "2009-09-14T14:06:35Z")

</div>

I’d like to be one of the cool kids who does “testing”. Yes, I know it’s  
essential.

Where do I start. I’d just like to start with a/some simple test.

My app users authlogic and i have an User.admin boolean flag.

I’d like to start by testing some stuff around this like only the  
current\_user or an Admin can delete their own Advert(s).

Any links tips to help start me off.

A User has many Adverts.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/testing/175474/2 "2009-09-14T14:30:25Z")

</div>

2009/9/14 bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> current\_user or an Admin can delete their own Advert(s).
> 
> Any links tips to help start me off.
> 
> A User has many Adverts.

Have you seen the rails guide on testing at  
[http://guides.rubyonrails.org/](http://guides.rubyonrails.org/) ?

Colin

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 3:04pm UTC](https://www.ruby-forum.com/t/testing/175474/3 "2009-09-14T15:04:10Z")

</div>

I’m just reading it. TDD is a bit much for me initially!

One question, trying to understand the stated example…

def test\_should\_not\_save\_post\_without\_title  
post = Post.new  
assert !post.save  
end

What does “!post.save” mean?  
If I’ve understood correctly this test is testing that a new post does  
NOT save?

Am I right?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 3:28pm UTC](https://www.ruby-forum.com/t/testing/175474/4 "2009-09-14T15:28:24Z")

</div>

bingo bob wrote:

> I’m just reading it. TDD is a bit much for me initially!

It’s actually a lot easier to write the tests first, because you can’t  
forget to write them! Also, the tests serve as documentation of what  
you meant the app to do. Adding tests to already written code – as  
you’re doing – requires lots of thought about what you meant originally  
and where the failure points could be.

> One question, trying to understand the stated example…
> 
> def test\_should\_not\_save\_post\_without\_title  
> post = Post.new  
> assert !post.save  
> end
> 
> What does “!post.save” mean?  
> If I’ve understood correctly this test is testing that a new post does  
> NOT save?

Yes.

By the way, I’d recommend that you try RSpec. I generally find its  
syntax and philosophy far more friendly than Rails’ own test framework.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

> Am I right?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 4:46pm UTC](https://www.ruby-forum.com/t/testing/175474/5 "2009-09-14T16:46:14Z")

</div>

2009/9/14 bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> What does “!post.save” mean?  
> If I’ve understood correctly this test is testing that a new post does  
> NOT save?
> 
> Am I right?

The clue is in the name of the test

Colin

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/testing/175474/6 "2009-09-14T15:16:39Z")

</div>

> What does “!post.save” mean?  
> If I’ve understood correctly this test is testing that a new post does  
> NOT save?
> 
> Am I right?

correct.

Fred
