Ticket #7802: dom_assertions_docs.2.diff
| File dom_assertions_docs.2.diff, 2.0 kB (added by jeremymcanally, 1 year ago) |
|---|
-
actionpack/lib/action_controller/assertions/dom_assertions.rb
old new 1 1 module ActionController 2 2 module Assertions 3 # A suite of assertions for verifying the DOM structure of provided markup. 4 # These are typically used for testing the structure of HTML or XML strings, usually 5 # views or HTML snippets generated by Rails. 3 6 module DomAssertions 4 # test 2 html strings to be equivalent, i.e. identical up to reordering of attributes 7 # Test two HTML or XML strings (<tt>expected</tt> and <tt>actual</tt>) to be equivalent (i.e., 8 # identical up to the reordering of attributes). The <tt>message</tt> parameter allows you to 9 # feed in a message that is displayed upon failure (useful if you want to make a note about what 10 # part of the view isn't being rendered correctly). 11 # 12 # Example: 13 # assert_dom_equal "<a href=\"http://www.rubyonrails.com\">Rails</a>", link_to("Rails", "http://www.rubyonrails.com") 14 # assert_dom_equal "<a href=\"account/login">Login</a>", link_to("Login", :action => 'login'), "Login link broken" 5 15 def assert_dom_equal(expected, actual, message="") 6 16 clean_backtrace do 7 17 expected_dom = HTML::Document.new(expected).root … … 11 21 end 12 22 end 13 23 14 # negated form of +assert_dom_equivalent+ 24 # This is a negated form of +assert_dom_equivalent+, that is, it tests that the HTML and/or XML strings are not equal. 25 # 26 # Example: 27 # assert_dom_not_equal "<img src=\"my_image.gif\">", image_tag("my_image.gif") 28 # assert_dom_not_equal "<a href=\"/home/index\">", link_to(:controller => 'home', :action => 'index') 15 29 def assert_dom_not_equal(expected, actual, message="") 16 30 clean_backtrace do 17 31 expected_dom = HTML::Document.new(expected).root