# Undefined method \`add\_assertion' for nil:NilClass

**URL:** <https://www.ruby-forum.com/t/undefined-method-add-assertion-for-nil-nilclass/55557>\
**Category:** Ruby\
**Created:** [March 22, 2006, 2:30am UTC](https://www.ruby-forum.com/t/undefined-method-add-assertion-for-nil-nilclass/55557 "2006-03-22T02:30:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [March 22, 2006, 2:30am UTC](https://www.ruby-forum.com/t/undefined-method-add-assertion-for-nil-nilclass/55557/1 "2006-03-22T02:30:55Z")

</div>

Hello,

I tried to use assertion’s the first time in my code and had absolutely  
now  
success. I always get following error:

TEST FAILED.undefined method `add_assertion' for nil:NilClass c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:115:in`add\_assertion’  
c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:353:in `_wrap_assertion' c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:38:in`assert’  
./utils.rb:1376:in `bpVerifyOnPage’

Here is a code snipe (verify is a string that is passed to a function):

The if statement works fine. The assert gives me trouble. Why? What is  
wrong? What is the nil class?  
I also tried assert(true), assert\_equal(“1234”,“1234”) with the same  
result

class BPUtils \< Test::Unit::TestCase

```
def initialize
end

def
 .........some code
   begin
   assert($ie.contains_text( verify ) )
   puts("TEST PASSED. Found test string #{verify}")

  #if $ie.contains_text( verify ) then
         	  # some
  	  #else
                  # some code
        #end

   rescue => e
puts("TEST FAILED." + e.message + "\n" + e.backtrace.join("\n"))

# hand exception over to main program to quit the program
      	raise QuitProgram, "quit program", caller
   end

```

end

---

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [March 22, 2006, 3:04am UTC](https://www.ruby-forum.com/t/undefined-method-add-assertion-for-nil-nilclass/55557/2 "2006-03-22T03:04:46Z")

</div>

Hi –

On Wed, 22 Mar 2006, Paatsch, Bernd wrote:

> Here is a code snipe (verify is a string that is passed to a function):
> 
> The if statement works fine. The assert gives me trouble. Why? What is  
> wrong? What is the nil class?  
> I also tried assert(true), assert\_equal(“1234”,“1234”) with the same result

The code you’re posted doesn’t compile, so it can’t be a real example  
of what’s not working. Can you provide a real example?

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)
