On Dec 1, 2008, at 2:14 PM, Maulin Pathare wrote:
> 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.


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 Biedenharn          http://agileconsultingllc.com
[EMAIL PROTECTED]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to