<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -168,6 +168,8 @@ module Merb::Test::Rspec::ViewMatchers
   
   class HasTag
     
+    attr_accessor :outer_has_tag, :inner_has_tag
+
     # ==== Parameters
     # tag&lt;~to_s&gt;:: The tag to look for.
     # attributes&lt;Hash&gt;:: Attributes for the tag (see below).
@@ -197,8 +199,13 @@ module Merb::Test::Rspec::ViewMatchers
 
       unless @blk.nil?
         !@document.search(selector).select do |ele|
-          @blk.call ele
-          true
+          begin
+            @blk.call ele
+            true
+          rescue Spec::Expectations::ExpectationNotMetError
+            @error_message = &quot;#{tag_for_error}:\n&quot; + $!.message
+            false
+          end
         end.empty?
       else
         !@document.search(selector).empty?
@@ -208,12 +215,10 @@ module Merb::Test::Rspec::ViewMatchers
     # ==== Returns
     # String:: The complete selector for element queries.
     def selector
-      @selector = &quot;//#{@tag}#{id_selector}#{class_selector}&quot;
-      @selector &lt;&lt; @attributes.map{|a, v| &quot;[@#{a}=\&quot;#{v}\&quot;]&quot;}.join
+      @selector = @outer_has_tag ? @outer_has_tag.selector : ''
 
-      @selector &lt;&lt; @inner_has_tag.selector unless @inner_has_tag.nil?
-
-      @selector
+      @selector &lt;&lt; &quot;//#{@tag}#{id_selector}#{class_selector}&quot;
+      @selector &lt;&lt; @attributes.map{|a, v| &quot;[@#{a}=\&quot;#{v}\&quot;]&quot;}.join
     end
 
     # ==== Returns
@@ -231,45 +236,38 @@ module Merb::Test::Rspec::ViewMatchers
     # ==== Returns
     # String:: The failure message.
     def failure_message
-      &quot;expected following output to contain a #{tag_for_error} tag:\n#{@document}&quot;
+      @error_message || &quot;expected following output to contain a #{tag_for_error} tag:\n#{@document}&quot;
     end
 
     # ==== Returns
     # String:: The failure message to be displayed in negative matches.
     def negative_failure_message
-      &quot;expected following output to omit a #{tag_for_error} tag:\n#{@document}&quot;
+      @error_message || &quot;expected following output to omit a #{tag_for_error} tag:\n#{@document}&quot;
     end
     
     # ==== Returns
     # String:: The tag used in failure messages.
     def tag_for_error
-      &quot;#{inner_failure_message}&lt;#{@tag}#{id_for_error}#{class_for_error}#{attributes_for_error}&gt;&quot;
-    end
-
-    # ==== Returns
-    # String::
-    #   The failure message to be displayed in negative matches within the
-    #   have_tag block.
-    def inner_failure_message
-      &quot;#{@inner_has_tag.tag_for_error} tag within a &quot; unless @inner_has_tag.nil?
+      result = &quot;#{@tag}#{id_for_error}#{class_for_error}#{attributes_for_error}&quot;
+      inner_has_tag ? result &lt;&lt; &quot; &gt; #{inner_has_tag.tag_for_error}&quot; : result
     end
 
     # ==== Returns
     # String:: ID for the error tag.
     def id_for_error
-      &quot; id=\&quot;#{@id}\&quot;&quot; unless @id.nil?
+      &quot;##{@id}&quot; unless @id.nil?
     end
 
     # ==== Returns
     # String:: Class for the error tag.
     def class_for_error
-      &quot; class=\&quot;#{@class}\&quot;&quot; unless @class.nil?
+      &quot;.#{@class}&quot; unless @class.nil?
     end
 
     # ==== Returns
     # String:: Class for the error tag.
     def attributes_for_error
-      @attributes.map{|a,v| &quot; #{a}=\&quot;#{v}\&quot;&quot;}.join
+      @attributes.map{|a,v| &quot;[#{a}=\&quot;#{v}\&quot;]&quot;}.join
     end
 
     # Search for a child tag within a have_tag block.
@@ -279,6 +277,7 @@ module Merb::Test::Rspec::ViewMatchers
     # attributes&lt;Hash&gt;:: Attributes for the tag (see below).
     def with_tag(name, attrs={})
       @inner_has_tag = HasTag.new(name, attrs)
+      @inner_has_tag.outer_has_tag = self
     end
   end
 </diff>
      <filename>lib/merb-core/test/matchers/view_matchers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>42da35e9861d0ca0ef228a017316a31d76cf0e29</id>
    </parent>
  </parents>
  <author>
    <name>Michael Holub</name>
    <email>michael.holub@gmail.com</email>
  </author>
  <url>http://github.com/wycats/merb-core/commit/1f6de2c3a0ec4bf42b4d6883e3898c2cc395f118</url>
  <id>1f6de2c3a0ec4bf42b4d6883e3898c2cc395f118</id>
  <committed-date>2008-10-11T21:30:50-07:00</committed-date>
  <authored-date>2008-10-10T18:56:39-07:00</authored-date>
  <message>#329 bug fix

Signed-off-by: Michael S. Klishin &lt;michael@novemberain.com&gt;</message>
  <tree>0935c21c912e5641c3abf0ec168bf014d75a7ea2</tree>
  <committer>
    <name>Michael S. Klishin</name>
    <email>michael@novemberain.com</email>
  </committer>
</commit>
