Forum: Ruby on Rails Default unit tests failing?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jon (Guest)
on 2006-01-10 03:02
(Received via mailing list)
I've got a strange issue.  My default unit tests are failing for two
models.  I
haven't changed _anything_ in the test.  Here's an example:

Output:
  1) Error:
test_truth(ShippingCostTypeTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.find

/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/
lib/active_record/fixtures.rb:456:in
`shipping_cost_types'
    test/unit/shipping_cost_type_test.rb:8:in `test_truth'



Fixture:
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
by_amount:
  id: 1
  name: amount
  code: AMT
by_quantity:
  id: 2
  name: Quantity
  code: QTY

Model:

class ShippingCostType < ActiveRecord::Base
end

-----

So, as you can tell, I'm _mighty_ perplexed.

Can anyone offer me some help?

Thanks much,
-jon
James (Guest)
on 2006-01-12 01:08
Jon wrote:
> I've got a strange issue.  My default unit tests are failing for two
> models.  I
> haven't changed _anything_ in the test.  Here's an example:
>
> Output:
>   1) Error:
> test_truth(ShippingCostTypeTest):
> NoMethodError: You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occured while evaluating nil.find
>
> /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/
> lib/active_record/fixtures.rb:456:in
> `shipping_cost_types'
>     test/unit/shipping_cost_type_test.rb:8:in `test_truth'
>

I'm having exactly the same problem/error message when trying to run a
basic test.  The dev machine is running Windows XP Pro, Ruby 1.82.15,
Rails 1.0.
James (Guest)
on 2006-01-12 01:19
Jon, here's how I got I working on mine. I added a setup method:

def setup
  @game = Game.find(1)
end

Then changed the default test_truth method to
def test_truth
  assert_kind_of Game, @game
end

Of course switch out the variables to, I guess, @shipping_cost_type and
such for your test.

Jon wrote:
> I've got a strange issue.  My default unit tests are failing for two
> models.  I
> haven't changed _anything_ in the test.  Here's an example:
>
> Output:
>   1) Error:
> test_truth(ShippingCostTypeTest):
> NoMethodError: You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occured while evaluating nil.find
>
> /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/
> lib/active_record/fixtures.rb:456:in
> `shipping_cost_types'
>     test/unit/shipping_cost_type_test.rb:8:in `test_truth'
>
>
>
> Fixture:
> # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
> by_amount:
>   id: 1
>   name: amount
>   code: AMT
> by_quantity:
>   id: 2
>   name: Quantity
>   code: QTY
>
> Model:
>
> class ShippingCostType < ActiveRecord::Base
> end
>
> -----
>
> So, as you can tell, I'm _mighty_ perplexed.
>
> Can anyone offer me some help?
>
> Thanks much,
> -jon
This topic is locked and can not be replied to.