Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    11module ActionController 
    22  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. 
    36    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" 
    515      def assert_dom_equal(expected, actual, message="") 
    616        clean_backtrace do 
    717          expected_dom = HTML::Document.new(expected).root 
     
    1121        end 
    1222      end 
    1323       
    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') 
    1529      def assert_dom_not_equal(expected, actual, message="") 
    1630        clean_backtrace do 
    1731          expected_dom = HTML::Document.new(expected).root