vamsi wrote:
> I am using this function : assert_equal(1,2) -->  when i execute this 
> imeediatley will get the error message and stops the script execution.
>
> insetad of that , is there any way to post failed message like "expected 1, 
> but it was 2"
>   

require 'test/unit/assertions'

module Watir
  # Verification methods
  module Assertions
  include Test::Unit::Assertions
    
    # Log a failure if the boolean is true. The message is the failure
    # message logged.
    # Whether true or false, the assertion count is incremented.
    def verify boolean, message = 'verify failed.'
      add_assertion
      add_failure message, caller unless boolean
    end
    
    def verify_equal expected, actual, message=nil
      full_message = build_message(message, <<EOT, expected, actual)
<?> expected but was
<?>.
EOT
      verify(expected == actual, full_message)
    end
    def verify_match pattern, string, message=nil
      pattern = case(pattern)
      when String
        Regexp.new(Regexp.escape(pattern))
      else
        pattern
      end
      full_message = build_message(message, "<?> expected to be 
=~\n<?>.", string, pattern)
      verify(string =~ pattern, full_message)
    end
    
  end

end

# Tests
# 3 tests, 10 assertions, 4 failures, 0 errors

class VerifyTests < Watir::TestCase
 
  def test_verify
    verify true
    assert true
    verify false
    assert true
  end
 
  def test_verify_equal
    verify_equal 1, 1
    verify_equal 1, 2
    verify_equal 3, 4
  end
 
  def test_verify_match
    verify_match /\d*/, '123'
    verify_match 'foo', 'foobar'
    verify_match '...', 'A'
  end
end

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to