# This is a wrapper of assert_select for rspec.moduleSpec# :nodoc:moduleRailsmoduleMatchersclassAssertSelect#:nodoc:definitialize(assertion,spec_scope,*args,&block)@assertion=assertion@spec_scope=spec_scope@args=args@block=blockenddefmatches?(response_or_text,&block)@block=blockifblockifdoc=doc_from(response_or_text)@args.unshift(doc)endbegin@spec_scope.__send__(@assertion,*@args,&@block)truerescue::Test::Unit::AssertionFailedError=>@errorfalseendenddeffailure_message_for_should;@error.message;enddeffailure_message_for_should_not;"should not #{description}, but did";enddefdescription{:assert_select=>"have tag#{format_args(*@args)}",:assert_select_email=>"send email#{format_args(*@args)}",}[@assertion]endprivatemoduleTestResponseOrStringdeftest_response?ActionController::TestResponse===selfand!self.headers['Content-Type'].blank?andself.headers['Content-Type'].to_sym==:xmlenddefstring?String===selfendenddefdoc_from(response_or_text)response_or_text.extendTestResponseOrStringmarkup=response_or_text.bodyifresponse_or_text.test_response?markup=response_or_textifresponse_or_text.string?HTML::Document.new(markup,false,true).rootifmarkupenddefformat_args(*args)args.empty??"":"(#{arg_list(*args)})"enddefarg_list(*args)args.mapdo|arg|arg.respond_to?(:description)?arg.description:arg.inspectend.join(", ")endend# :call-seq:# response.should have_tag(*args, &block)# string.should have_tag(*args, &block)## wrapper for assert_select with additional support for using# css selectors to set expectation on Strings. Use this in# helper specs, for example, to set expectations on the results# of helper methods.## == Examples## # in a controller spec# response.should have_tag("div", "some text")## # in a helper spec (person_address_tag is a method in the helper)# person_address_tag.should have_tag("input#person_address")## see documentation for assert_select at http://api.rubyonrails.org/defhave_tag(*args,&block)@__current_scope_for_assert_select=AssertSelect.new(:assert_select,self,*args,&block)end# wrapper for a nested assert_select## response.should have_tag("div#form") do# with_tag("input#person_name[name=?]", "person[name]")# end## see documentation for assert_select at http://api.rubyonrails.org/defwith_tag(*args,&block)@__current_scope_for_assert_select.shouldhave_tag(*args,&block)end# wrapper for a nested assert_select with false## response.should have_tag("div#1") do# without_tag("span", "some text that shouldn't be there")# end## see documentation for assert_select at http://api.rubyonrails.org/defwithout_tag(*args,&block)@__current_scope_for_assert_select.should_nothave_tag(*args,&block)end# :call-seq:# response.should have_rjs(*args, &block)## wrapper for assert_select_rjs## see documentation for assert_select_rjs at http://api.rubyonrails.org/defhave_rjs(*args,&block)AssertSelect.new(:assert_select_rjs,self,*args,&block)end# :call-seq:# response.should send_email(*args, &block)## wrapper for assert_select_email## see documentation for assert_select_email at http://api.rubyonrails.org/defsend_email(*args,&block)AssertSelect.new(:assert_select_email,self,*args,&block)end# wrapper for assert_select_encoded## see documentation for assert_select_encoded at http://api.rubyonrails.org/defwith_encoded(*args,&block)shouldAssertSelect.new(:assert_select_encoded,self,*args,&block)endendendend