# Unit Testing and assert\_match

**URL:** <https://www.ruby-forum.com/t/unit-testing-and-assert-match/81946>\
**Category:** Rails\
**Created:** [January 16, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/unit-testing-and-assert-match/81946 "2007-01-16T13:44:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draconid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@Draconid](https://www.ruby-forum.com/u/Draconid)\
**Post date:** [January 16, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/unit-testing-and-assert-match/81946/1 "2007-01-16T13:44:17Z")

</div>

I’m trying to ensure that various fields are saved to the database  
without html, by stripping tags in before\_save. However I’m having  
trouble setting up the unit test for this and I’m not sure if it’s my  
code or my test that’s wrong.

The model code is:

def before\_save  
self.first\_name = strip\_tags(self.first\_name)  
self.last\_name = strip\_tags(self.last\_name)  
self.organisation = strip\_tags(self.organisation)  
end

The relevant part of my unit test is (obviously I’m doing for each item  
in the before\_save bit, but since it’s all the same I’m just showing the  
one):

```
c = Contact.new
c.first_name = "this"
c.last_name = "<html>that</html>"
c.organisation = "there"
c.email='removed_email_address@domain.invalid'
c.save

assert_match("that", c.last_name)

```

Problem is that if I do assert\_match(“that”, c.last\_name)  
it also matches.

What’s my problem? Is it the code or the test?

Also, could someone help me with an assert\_no\_match regexp. I hate  
regexps! I would like to do an assert\_no\_match with that -  
except I don’t know how to do a regular expression to check for an exact  
match with this.

Thanks to any help I can get!

---

<div class="post-metadata">

**Author:** ![Draconid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@Draconid](https://www.ruby-forum.com/u/Draconid)\
**Post date:** [January 16, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/unit-testing-and-assert-match/81946/2 "2007-01-16T23:14:57Z")

</div>

Try R.Tidy plugin :  
[http://www.agilewebdevelopment.com/plugins/railstidy](http://www.agilewebdevelopment.com/plugins/railstidy)
