Hello all, I''m trying to assert_tag the following rhtml line : <%= link_to "Cancel", {:controller=>"project", :action=>"show", :id=>@project.ProjectID} , {:class=>"button"}%> The html source output is : <a class="button" href="/project/show/163">Cancel</a> But this test : assert_tag :tag=>"a", :attributes=>{:id=>"href"}, :child=>"Cancel" Returns : [C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/assertions.rb:240:in `assert_tag'' test/functional/model_controller_test.rb:69:in `testAutoLinkPreviewHtml'']: expected tag, but no tag found matching {:tag=>"a", :child=>"Cancel", :attributes=>{:id=>"href"}} in: Also, how can I test the content of the href ? Thanks. Peter Fitzgibbons
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Oct-07 21:07 UTC
Re: assert_tag for a hyperlink field ?
Hi ! Peter Fitzgibbons said the following on 2005-10-07 16:02:> I''m trying to assert_tag the following rhtml line : > > <%= link_to "Cancel", {:controller=>"project", :action=>"show", > :id=>@project.ProjectID} , {:class=>"button"}%> > > > The html source output is : > > <a class="button" href="/project/show/163">Cancel</a> > > But this test : > > assert_tag :tag=>"a", :attributes=>{:id=>"href"}, :child=>"Cancel"That should be (warning untested, but should be close): assert_tag :tag => ''a'', :attributes=> {:href => ''/project/show/163''}, :content => ''Cancel'' I too find that assert_tag is pretty confusing. It sure is a VERY powerful way to test your source, the interface might need something better though. Something like Builder ? Hope that helps ! François
Thanks Francois! Yes, I''m loving the assert_tag. Do you happen to know ? (warning, previous posts exist) 1. How to test flash when i set it in the #get method of a functional test ? 2. How to validate an XHTML page via unit test ? Thanks ! On 10/7/05, rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> wrote:> > Hi ! > > Peter Fitzgibbons said the following on 2005-10-07 16:02: > > I''m trying to assert_tag the following rhtml line : > > > > <%= link_to "Cancel", {:controller=>"project", :action=>"show", > > :id=>@project.ProjectID} , {:class=>"button"}%> > > > > > > The html source output is : > > > > <a class="button" href="/project/show/163">Cancel</a> > > > > But this test : > > > > assert_tag :tag=>"a", :attributes=>{:id=>"href"}, :child=>"Cancel" > > That should be (warning untested, but should be close): > assert_tag :tag => ''a'', :attributes=> {:href => ''/project/show/163''}, > :content => ''Cancel'' > > I too find that assert_tag is pretty confusing. It sure is a VERY > powerful way to test your source, the interface might need something > better though. Something like Builder ? > > Hope that helps ! > François > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails