# Trying out TDD, getting stuck!

**URL:** <https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149>\
**Category:** Rails\
**Created:** [January 19, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149 "2009-01-19T21:11:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 19, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/1 "2009-01-19T21:11:39Z")

</div>

I’ve heard about TDD, read about TDD, and now I’m trying to practice it.  
However, I’m getting stuck trying to do a simple test in rails 2.2.2.  
I’ve decided to try writing a simple functional test to test the  
‘add\_item’ action of my cart controller.

However, I got as far as this before my test was already not running:

test “should add an item to the cart” do

end

My cart controller uses two ‘fake’ models (cart\_session,  
cart\_session\_line\_item) that aren’t activerecords. however i’m getting  
this error message:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:  
cart\_sessi  
on\_line\_items: DELETE FROM “cart\_session\_line\_items” WHERE 1=1

for the life of me, I don’t understand why my test would be hitting the  
database yet when my test body is blank and why it thinks that  
cart\_session\_line\_item is an activerecord when it’s not wired up as  
such.

i know TDD is a good thing, and any help would be greatly appreciated!

Thanks,  
Nelson

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 19, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/2 "2009-01-19T22:06:54Z")

</div>

On Jan 19, 2:11 pm, Nelson H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> cart\_session\_line\_item is an activerecord when it’s not wired up as  
> such.

Are you sure your models are not inheriting from ActiveRecord::Base?

Even if you’re not calling any methods on them yet, the sheer act of  
deriving from ActiveRecord::Base will necessitate the presence of  
those tables.

> i know TDD is a good thing, and any help would be greatly appreciated!
> 
> Thanks,  
> Nelson

TDD is a good thing! Let’s see if we can’t get this working for you.

Jeff

> **[Jeffrey Cohen · Purple Workshops](https://purpleworkshops.com/)**
>
> Jeffrey Cohen — building The Aha Map, leading Software for Research, teaching at the University of Chicago, and running Purple Workshops.

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 19, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/3 "2009-01-19T23:32:44Z")

</div>

Nelson H. wrote:

> > Are you sure your models are not inheriting from ActiveRecord::Base?
> > 
> > Even if you’re not calling any methods on them yet, the sheer act of  
> > deriving from ActiveRecord::Base will necessitate the presence of  
> > those tables.
> 
> Thanks for the response! I just double checked the two models and  
> neither of them derive from ActiveRecord::Base.

Can you post the source to either class?  
Also note that inheritance is not equal to derivation.

–  
Roderick van Domburg  
[http://www.nedforce.com](http://www.nedforce.com)

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 19, 2009, 10:40pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/4 "2009-01-19T22:40:41Z")

</div>

Jeff C. wrote:

> Are you sure your models are not inheriting from ActiveRecord::Base?
> 
> Even if you’re not calling any methods on them yet, the sheer act of  
> deriving from ActiveRecord::Base will necessitate the presence of  
> those tables.

Thanks for the response! I just double checked the two models and  
neither of them derive from ActiveRecord::Base.

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 4:34am UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/5 "2009-01-20T04:34:14Z")

</div>

Nelson H. wrote:

> Thanks for the response! I just double checked the two models and  
> neither of them derive from ActiveRecord::Base.

Use ‘script/generate model my\_model’ to generate models. They will come  
complete  
with empty unit tests, empty data fixtures, etc.

Then, learn TDD using the “unit” tests, meaning the tests on the models

- not  
the “functional” tests on the controllers!

Anything your users can do to data thru the view and controllers, your  
unit  
tests should be able to do to the model objects thru their public  
methods.

Only after you are proficient at the “unit” tests should you try more  
advanced  
and indirect testing!

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 1:12am UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/6 "2009-01-20T01:12:56Z")

</div>

Roderick van Domburg wrote:

> Can you post the source to either class?

cart\_session.rb

class CartSession  
attr :items  
attr\_accessor :building  
attr\_accessor :use\_corporate\_account  
end

class CartSessionLineItem  
attr\_accessor :sku, :quantity, :sku\_id

def initialize(sku\_id, quantity)  
@sku\_id = sku\_id  
@sku = Sku.find(sku\_id)  
@quantity = quantity  
end

def total  
sku.skuable.price \* quantity  
end

end

> Also note that inheritance is not equal to derivation.

OK, I have to admit, I feel dumb here. I always thought inheriting from  
a class was deriving from it. Is my terminology all messed up?

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 2:14pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/7 "2009-01-20T14:14:33Z")

</div>

On Tuesday 20 January 2009 03:50 am, Roderick van Domburg wrote:

> I take that back and you are right. Must have had my head up in the  
> clouds at that time of writing. 🙂

Maybe me too–I’ve been watching this thread waiting for a clue as to  
what TDD is–my out of the blue guess is Top Down Design, but I’ll do  
better to ask…?

## Randy K.

I didn’t have time to write a short letter, so I created a video  
instead.–with apologies to Cicero, et.al.

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 2:20pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/8 "2009-01-20T14:20:30Z")

</div>

Randy K. wrote:

> On Tuesday 20 January 2009 03:50 am, Roderick van Domburg wrote:
> 
> > I take that back and you are right. Must have had my head up in the  
> > clouds at that time of writing. 🙂
> 
> Maybe me too–I’ve been watching this thread waiting for a clue as to  
> what TDD is–my out of the blue guess is Top Down Design, but I’ll do  
> better to ask…?
> 
> Randy K.

not a bad guess, but try Test Driven Design/Development.

> **[Test-driven development](https://en.wikipedia.org/wiki/Test-driven_development)**
>
> Test-driven development (TDD) is a way to write source code that involves writing an automated unit-level test case that fails, then writing just enough code to make the test pass, then refactoring both the test code and the production code, then repeating with another new test case. Alternative approaches to writing automated tests is to write all of the production code before starting on the test code or to write all of the test code before starting on the production code. With TDD, both are wr...

HTH

Matt

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 3:31pm UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/9 "2009-01-20T15:31:11Z")

</div>

On Tuesday 20 January 2009 08:19 am, Matt H. wrote:

> not a bad guess, but try Test Driven Design/Development.
> 
> [Test-driven development - Wikipedia](http://en.wikipedia.org/wiki/Test-driven_development)
> 
> HTH

Matt,

Yes, thank you!

## Randy K.

I didn’t have time to write a short letter, so I created a video  
instead.–with apologies to Cicero, et.al.

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [February 7, 2009, 2:37am UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/10 "2009-02-07T02:37:57Z")

</div>

Well, I figured it out, so I’m going to update my thread and hopefully  
help someone in the future.

The problem was in test\_helper.rb on this line:

fixtures :all

Anyways, thanks for everyone’s responses. And thanks to Phlip’s  
suggestion about starting out with unit tests. They were much easier to  
start with, and now I feel more comfortable with tests.

Randy K. wrote:

> On Tuesday 20 January 2009 08:19 am, Matt H. wrote:
> 
> > not a bad guess, but try Test Driven Design/Development.
> > 
> > [Test-driven development - Wikipedia](http://en.wikipedia.org/wiki/Test-driven_development)
> > 
> > HTH
> 
> Matt,
> 
> Yes, thank you!
> 
> ## Randy K.
> 
> I didn’t have time to write a short letter, so I created a video  
> instead.–with apologies to Cicero, et.al.

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [January 20, 2009, 9:50am UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/11 "2009-01-20T09:50:39Z")

</div>

Nelson H. wrote:

> cart\_session.rb
> 
> class CartSession  
> attr :items  
> attr\_accessor :building  
> attr\_accessor :use\_corporate\_account  
> end
> 
> class CartSessionLineItem  
> attr\_accessor :sku, :quantity, :sku\_id
> 
> def initialize(sku\_id, quantity)  
> @sku\_id = sku\_id  
> @sku = Sku.find(sku\_id)  
> @quantity = quantity  
> end
> 
> def total  
> sku.skuable.price \* quantity  
> end
> 
> end

That looks right. Is there perhaps a fixture lingering around?

> > Also note that inheritance is not equal to derivation.
> 
> OK, I have to admit, I feel dumb here. I always thought inheriting from  
> a class was deriving from it. Is my terminology all messed up?

I take that back and you are right. Must have had my head up in the  
clouds at that time of writing. 🙂

–  
Roderick van Domburg  
[http://www.nedforce.com](http://www.nedforce.com)

---

<div class="post-metadata">

**Author:** ![nelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@nelson](https://www.ruby-forum.com/u/nelson)\
**Post date:** [February 7, 2009, 2:38am UTC](https://www.ruby-forum.com/t/trying-out-tdd-getting-stuck/158149/12 "2009-02-07T02:38:31Z")

</div>

Oops… I forgot the actual fix. The fix was to comment out:

fixtures :all
