public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
#329 bug fix

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
mholub (author)
Fri Oct 10 18:56:39 -0700 2008
michaelklishin (committer)
Sat Oct 11 21:30:50 -0700 2008
commit  1f6de2c3a0ec4bf42b4d6883e3898c2cc395f118
tree    0935c21c912e5641c3abf0ec168bf014d75a7ea2
parent  42da35e9861d0ca0ef228a017316a31d76cf0e29
...
168
169
170
 
 
171
172
173
...
197
198
199
200
201
 
 
 
 
 
 
 
202
203
204
...
208
209
210
211
212
 
213
214
215
216
 
 
217
218
219
...
231
232
233
234
 
235
236
237
238
239
240
 
241
242
243
244
245
246
247
248
249
250
251
252
253
254
 
 
255
256
257
258
259
260
 
261
262
263
264
265
266
 
267
268
269
270
271
272
 
273
274
275
...
279
280
281
 
282
283
284
...
168
169
170
171
172
173
174
175
...
199
200
201
 
 
202
203
204
205
206
207
208
209
210
211
...
215
216
217
 
 
218
219
 
 
 
220
221
222
223
224
...
236
237
238
 
239
240
241
242
243
244
 
245
246
247
248
249
250
 
 
 
 
 
 
 
 
 
251
252
253
254
255
256
257
 
258
259
260
261
262
263
 
264
265
266
267
268
269
 
270
271
272
273
...
277
278
279
280
281
282
283
0
@@ -168,6 +168,8 @@ module Merb::Test::Rspec::ViewMatchers
0
   
0
   class HasTag
0
     
0
+    attr_accessor :outer_has_tag, :inner_has_tag
0
+
0
     # ==== Parameters
0
     # tag<~to_s>:: The tag to look for.
0
     # attributes<Hash>:: Attributes for the tag (see below).
0
@@ -197,8 +199,13 @@ module Merb::Test::Rspec::ViewMatchers
0
 
0
       unless @blk.nil?
0
         !@document.search(selector).select do |ele|
0
-          @blk.call ele
0
-          true
0
+          begin
0
+            @blk.call ele
0
+            true
0
+          rescue Spec::Expectations::ExpectationNotMetError
0
+            @error_message = "#{tag_for_error}:\n" + $!.message
0
+            false
0
+          end
0
         end.empty?
0
       else
0
         !@document.search(selector).empty?
0
@@ -208,12 +215,10 @@ module Merb::Test::Rspec::ViewMatchers
0
     # ==== Returns
0
     # String:: The complete selector for element queries.
0
     def selector
0
-      @selector = "//#{@tag}#{id_selector}#{class_selector}"
0
-      @selector << @attributes.map{|a, v| "[@#{a}=\"#{v}\"]"}.join
0
+      @selector = @outer_has_tag ? @outer_has_tag.selector : ''
0
 
0
-      @selector << @inner_has_tag.selector unless @inner_has_tag.nil?
0
-
0
-      @selector
0
+      @selector << "//#{@tag}#{id_selector}#{class_selector}"
0
+      @selector << @attributes.map{|a, v| "[@#{a}=\"#{v}\"]"}.join
0
     end
0
 
0
     # ==== Returns
0
@@ -231,45 +236,38 @@ module Merb::Test::Rspec::ViewMatchers
0
     # ==== Returns
0
     # String:: The failure message.
0
     def failure_message
0
-      "expected following output to contain a #{tag_for_error} tag:\n#{@document}"
0
+      @error_message || "expected following output to contain a #{tag_for_error} tag:\n#{@document}"
0
     end
0
 
0
     # ==== Returns
0
     # String:: The failure message to be displayed in negative matches.
0
     def negative_failure_message
0
-      "expected following output to omit a #{tag_for_error} tag:\n#{@document}"
0
+      @error_message || "expected following output to omit a #{tag_for_error} tag:\n#{@document}"
0
     end
0
     
0
     # ==== Returns
0
     # String:: The tag used in failure messages.
0
     def tag_for_error
0
-      "#{inner_failure_message}<#{@tag}#{id_for_error}#{class_for_error}#{attributes_for_error}>"
0
-    end
0
-
0
-    # ==== Returns
0
-    # String::
0
-    #   The failure message to be displayed in negative matches within the
0
-    #   have_tag block.
0
-    def inner_failure_message
0
-      "#{@inner_has_tag.tag_for_error} tag within a " unless @inner_has_tag.nil?
0
+      result = "#{@tag}#{id_for_error}#{class_for_error}#{attributes_for_error}"
0
+      inner_has_tag ? result << " > #{inner_has_tag.tag_for_error}" : result
0
     end
0
 
0
     # ==== Returns
0
     # String:: ID for the error tag.
0
     def id_for_error
0
-      " id=\"#{@id}\"" unless @id.nil?
0
+      "##{@id}" unless @id.nil?
0
     end
0
 
0
     # ==== Returns
0
     # String:: Class for the error tag.
0
     def class_for_error
0
-      " class=\"#{@class}\"" unless @class.nil?
0
+      ".#{@class}" unless @class.nil?
0
     end
0
 
0
     # ==== Returns
0
     # String:: Class for the error tag.
0
     def attributes_for_error
0
-      @attributes.map{|a,v| " #{a}=\"#{v}\""}.join
0
+      @attributes.map{|a,v| "[#{a}=\"#{v}\"]"}.join
0
     end
0
 
0
     # Search for a child tag within a have_tag block.
0
@@ -279,6 +277,7 @@ module Merb::Test::Rspec::ViewMatchers
0
     # attributes<Hash>:: Attributes for the tag (see below).
0
     def with_tag(name, attrs={})
0
       @inner_has_tag = HasTag.new(name, attrs)
0
+      @inner_has_tag.outer_has_tag = self
0
     end
0
   end
0
 

Comments