Topic: Unit Testing and assert_match
I'm not sure if this is a problem with the code that the test is testing, or the test itself, but I think it's the test so I'm putting it in this section.
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:
self.first_name = strip_tags(self.first_name)
self.last_name = strip_tags(self.last_name)
self.organisation = strip_tags(self.organisation)
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
c = Contact.new
c.first_name = "this"
c.last_name = "<html>that</html>"
c.organisation = "there"
Problem is that if I do assert_match("<html>that</html>", 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 <html>that</html> -
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!
Last edited by Draconid (2007-01-16 11:24:28)