title: Unit Testing How To Fail a Test for Validates Format of URL
body: <p>I have a model that requires a valid format of a URL. </p>
  
  <pre><code>class Event &lt; ActiveRecord::Base
  
    validates_format_of :url, :with =&gt; /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
  
  end
  </code></pre>
  
  <p><strong>BUT BEFORE</strong> implementing the solution I want to write a test that fails. Is this how someone would go about writing a failed test? (Please no Rspec or Shoulda solution trying to stick with basics before going to advanced testing / matcher frameworks.</p>
  
  <pre><code>class EventTest &lt; ActiveSupport::TestCase
  
  setup do
  # These attributes are valid
  @event_attributes = { :title =&gt; "A title",
                        :url =&gt; "http://somedomain.com/images/land.jpg",}
  end
  
  test "should not be valid with an INVALID URL" do
      @event = Event.new(@event_attributes.merge(:url =&gt; "htp:/domain"))
      assert_no_match(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix, @event.url, "Not a valid format")   
    end
  
  end
  </code></pre>
  
  <p>Is the <code>assert_no_match</code> the right approach. Any suggestions.</p>