Forum: Ruby on Rails weird error when running my unit tests

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.
Alain (Guest)
on 2006-04-30 20:40
How can this be possible:

I have two tests:

  def find_all_active_and_inactive
    assert_equal Concept.find_all_active_and_inactive.size,
@concepts.size
  end

and

  def test_find_all_inactive
    assert_equal Concept.find_all_inactive.size, (@concepts.size -
Concept.find_all.size)
  end

Concept.find_all returns 2 concepts (I overwrote the method to return
only the active concepts)
Concept.find_all_inactive returns 1 concept
Concept.find_all_active_and_inactive returns 3 concepts

And @concepts.size returns 3

When I run the first test, there is no error.

When I run the second test, I get this error:

1) Error:
test_find_all_inactive(ConceptTest):
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.size
    concept_test.rb:36:in `test_find_all_inactive'

I dont understand! Why is @concepts.size working in the first test and
not in the second?
This topic is locked and can not be replied to.