# Re: undefined method \`add\_assertion' for nil:NilClass

**URL:** <https://www.ruby-forum.com/t/re-undefined-method-add-assertion-for-nil-nilclass/85041>\
**Category:** Ruby\
**Created:** [March 22, 2006, 3:39am UTC](https://www.ruby-forum.com/t/re-undefined-method-add-assertion-for-nil-nilclass/85041 "2006-03-22T03:39:45Z")\
**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, 3:39am UTC](https://www.ruby-forum.com/t/re-undefined-method-add-assertion-for-nil-nilclass/85041/1 "2006-03-22T03:39:45Z")

</div>

I started with ruby about 6 weeks ago. So I am pretty new. The code I  
have  
contains out of 4 files and works only with a specific underlying  
application, which I manipulate through the code. Maybe I am  
misuderstanding  
the use of assertions. I thought that assertions help raising errors. I  
don’t want to run a Unittest. So maybe my approach is wrong?  
I removee \< Test::Unit::TestCase

Now I get:  
TEST FAILED.undefined method `assert’ for #WebAC::BPUtils:0x2c2e270

My code:  
#Includes  
require ‘test/unit/assertions’  
require ‘test/unit’

# more code

$clsBPUtils = BPUtils.new

# more code

class BPUtils  
require ‘test/unit/assertions’

```
def initialize
    # empty
end

def bpVerifyPopupWindowOpen( ieCont, verify)
  begin
  assert( ieCont.contains_text( verify) )
  puts("TEST PASSED. Found test string 'Programming Ruby' ")

```

rescue =\> e  
puts(“TEST FAILED.” + e.message + “\n” +  
e.backtrace.join("\n"))  
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, 10:41am UTC](https://www.ruby-forum.com/t/re-undefined-method-add-assertion-for-nil-nilclass/85041/2 "2006-03-22T10:41:09Z")

</div>

Hi Bernd

if your parameter ieCont (I hope that does not mean what I am afraid it  
does  
mean 😉  
is nil it cannot respond to the method contains\_text and that seems to  
be  
your problem.  
It seems you did not pass an object of the expected type.

It does not really have anything to do with assert, only that the stack  
trace becomes a little bit confusing sometimes.

Cheers  
Robert

On 3/22/06, Paatsch, Bernd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> TEST FAILED.undefined method `assert' for #<WebAC::BPUtils:0x2c2e270> class BPUtils rescue => e Subject: Re: undefined method `add\_assertion’ for nil:NilClass
> 
> > TEST FAILED.undefined method `add\_assertion’ for nil:NilClass  
> > result
> 
> “Ruby for Rails” chapters now available  
> from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein
