Forum: Ruby on Rails Unit Testing and assert_match

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Draconid (Guest)
on 2007-01-16 14:44
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)

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 =
    c.first_name = "this"
    c.last_name = "<html>that</html>"
    c.organisation = "there"'removed_email_address@domain.invalid'

    assert_match("that", c.last_name)

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!
Bala P. (Guest)
on 2007-01-17 00:14
(Received via mailing list)
This topic is locked and can not be replied to.