# Rake test:units failing

**URL:** <https://www.ruby-forum.com/t/rake-test-units-failing/154577>\
**Category:** Rails\
**Created:** [December 1, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577 "2008-12-01T20:14:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 1, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/1 "2008-12-01T20:14:31Z")

</div>

Hello,  
I am a rails beginner and am having some trouble running the unit tests  
using rake. i am following the example in the simply rails 2 book.

I have a simple model with one field “name” and a validation for name  
that it cannot be empty

my test file looks like this

1. require ‘test\_helper’
2. 
3. class LadderTest \< ActiveSupport::TestCase
4. 
5. def test\_create\_ladder\_name\_error
6. 

```
l = Ladder.create(:name => nil)

```

7. 

```
assert l.error.on(:name)

```

8. end
9. 
10. end

When I run rake test:units from the shell I get the following error

rake aborted!  
You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]

I am running rails version 2.2.2

Does anyone know whats wrong? Thanks.

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 1, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/2 "2008-12-01T22:32:35Z")

</div>

On Dec 1, 2008, at 2:14 PM, Maulin P. wrote:

> When I run rake test:units from the shell I get the following error
> 
> rake aborted!  
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of ActiveRecord::Base.  
> The error occurred while evaluating nil.[]
> 
> I am running rails version 2.2.2
> 
> Does anyone know whats wrong? Thanks.

Perhaps you need a line between 6 & 7 with:

```
assert !l.valid?

```

Otherwise the error object associated to the model will not have been  
created.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 2, 2008, 1:05am UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/3 "2008-12-02T01:05:43Z")

</div>

Rob B. wrote:

> On Dec 1, 2008, at 2:14 PM, Maulin P. wrote:
> 
> > When I run rake test:units from the shell I get the following error
> > 
> > rake aborted!  
> > You have a nil object when you didn’t expect it!  
> > You might have expected an instance of ActiveRecord::Base.  
> > The error occurred while evaluating nil.[]
> > 
> > I am running rails version 2.2.2
> > 
> > Does anyone know whats wrong? Thanks.
> 
> Perhaps you need a line between 6 & 7 with:
> 
> ```
> assert !l.valid?
> 
> ```
> 
> Otherwise the error object associated to the model will not have been  
> created.
> 
> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

Hey,  
Thanks for the reply. The assert !l.valid? did not help. I still get the  
same error.

When I run the command with the --trace command, I can see that rake  
fails right after the execute db:test:purge step. I have included the  
trace.

\*\* Invoke test:units (first\_time)  
\*\* Invoke db:test:prepare (first\_time)  
\*\* Invoke db:abort\_if\_pending\_migrations (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:abort\_if\_pending\_migrations  
\*\* Execute db:test:prepare  
\*\* Invoke db:test:load (first\_time)  
\*\* Invoke db:test:purge (first\_time)  
\*\* Invoke environment  
\*\* Execute db:test:purge  
rake aborted!  
You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]  
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:341  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke\_prerequisites’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke\_prerequisites’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke’  
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:372  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke\_prerequisites’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke\_prerequisites’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in  
`invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in  
`invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in  
`standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard\_exception\_handling’  
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31 /usr/bin/rake:19:in `load’  
/usr/bin/rake:19

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 2, 2008, 1:26am UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/4 "2008-12-02T01:26:12Z")

</div>

Hey Rob,  
That was a typo on my part. My code actually has l.errors.on(:name).  
Heres the pastebin link to the code  
[http://pastebin.com/m7cae6ae3](http://pastebin.com/m7cae6ae3)

Rob B. wrote:

> I think you mean to have:
> 
> l.errors.on(:name)  
> Note: ‘errors’, not ‘error’
> 
> -Rob
> 
> On Dec 1, 2008, at 7:05 PM, Maulin P. wrote:
> 
> > > > The error occurred while evaluating nil.[]  
> > > > Otherwise the error object associated to the model will not have been  
> > > > same error.
> > 
> > When I run the command with the --trace command, I can see that rake  
> > fails right after the execute db:test:purge step. I have included the  
> > trace.
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid  
> +1 513-295-4739  
> Skype: rob.biedenharn

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 2, 2008, 1:20am UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/5 "2008-12-02T01:20:44Z")

</div>

I think you mean to have:

l.errors.on(:name)  
Note: ‘errors’, not ‘error’

-Rob

On Dec 1, 2008, at 7:05 PM, Maulin P. wrote:

> > > The error occurred while evaluating nil.[]  
> > > Otherwise the error object associated to the model will not have been  
> > > same error.
> 
> When I run the command with the --trace command, I can see that rake  
> fails right after the execute db:test:purge step. I have included the  
> trace.

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739  
Skype: rob.biedenharn

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 2, 2008, 1:52am UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/6 "2008-12-02T01:52:08Z")

</div>

I figured it out, and it was dumb!  
I had commented out the test database settings from the database.yaml  
file. uncommenting them fixed the problem 🙂

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 2, 2008, 2:37am UTC](https://www.ruby-forum.com/t/rake-test-units-failing/154577/7 "2008-12-02T02:37:57Z")

</div>

On Dec 1, 2008, at 7:52 PM, Maulin P. wrote:

> I figured it out, and it was dumb!  
> I had commented out the test database settings from the database.yaml  
> file. uncommenting them fixed the problem 🙂

the dumb ones hurt the most 😉

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
