diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions')
5 files changed, 14 insertions, 32 deletions
| diff --git a/actionpack/lib/action_dispatch/testing/assertions/dom.rb b/actionpack/lib/action_dispatch/testing/assertions/dom.rb index edea6dab39..7dc3d0f97c 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/dom.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/dom.rb @@ -5,11 +5,8 @@ module ActionDispatch      module DomAssertions        # \Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)        # -      # ==== Examples -      #        #   # assert that the referenced method generates the appropriate HTML string        #   assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com") -      #        def assert_dom_equal(expected, actual, message = "")          expected_dom = HTML::Document.new(expected).root          actual_dom   = HTML::Document.new(actual).root @@ -18,11 +15,8 @@ module ActionDispatch        # The negated form of +assert_dom_equivalent+.        # -      # ==== Examples -      #        #   # assert that the referenced method does not generate the specified HTML string        #   assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com") -      #        def assert_dom_not_equal(expected, actual, message = "")          expected_dom = HTML::Document.new(expected).root          actual_dom   = HTML::Document.new(actual).root diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 8f6fff5d32..b4c8f839ac 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -15,14 +15,11 @@ module ActionDispatch        # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.        # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.        # -      # ==== Examples -      #        #   # assert that the response was a redirection        #   assert_response :redirect        #        #   # assert that the response code was status code 401 (unauthorized)        #   assert_response 401 -      #        def assert_response(type, message = nil)          message ||= "Expected response to be a <#{type}>, but was <#{@response.response_code}>" @@ -31,7 +28,7 @@ module ActionDispatch              assert @response.send("#{type}?"), message            else              code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type] -            assert_equal @response.response_code, code, message +            assert_equal code, @response.response_code, message            end          else            assert_equal type, @response.response_code, message @@ -42,8 +39,6 @@ module ActionDispatch        # This match can be partial, such that <tt>assert_redirected_to(:controller => "weblog")</tt> will also        # match the redirection of <tt>redirect_to(:controller => "weblog", :action => "show")</tt> and so on.        # -      # ==== Examples -      #        #   # assert that the redirection was to the "index" action on the WeblogController        #   assert_redirected_to :controller => "weblog", :action => "index"        # @@ -55,7 +50,6 @@ module ActionDispatch        #        #   # asserts that the redirection matches the regular expression        #   assert_redirected_to %r(\Ahttp://example.org) -      #        def assert_redirected_to(options = {}, message=nil)          assert_response(:redirect, message)          return true if options === @response.location diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1f4b905d18..41fa3a4b95 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -26,7 +26,6 @@ module ActionDispatch        #        # The +message+ parameter allows you to pass in an error message that is displayed upon failure.        # -      # ==== Examples        #   # Check the default route (i.e., the index action)        #   assert_recognizes({:controller => 'items', :action => 'index'}, 'items')        # @@ -57,7 +56,6 @@ module ActionDispatch        #        # The +defaults+ parameter is unused.        # -      # ==== Examples        #   # Asserts that the default action is generated for a route with no action        #   assert_generates "/items", :controller => "items", :action => "index"        # @@ -71,11 +69,9 @@ module ActionDispatch        #   assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" }        def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)          if expected_path =~ %r{://} -          begin +          fail_on(URI::InvalidURIError) do              uri = URI.parse(expected_path)              expected_path = uri.path.to_s.empty? ? "/" : uri.path -          rescue URI::InvalidURIError => e -            raise ActionController::RoutingError, e.message            end          else            expected_path = "/#{expected_path}" unless expected_path.first == '/' @@ -100,7 +96,6 @@ module ActionDispatch        # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The        # +message+ parameter allows you to specify a custom error message to display upon failure.        # -      # ==== Examples        #  # Assert a basic route: a controller with the default action (index)        #  assert_routing '/home', :controller => 'home', :action => 'index'        # @@ -192,14 +187,12 @@ module ActionDispatch            request = ActionController::TestRequest.new            if path =~ %r{://} -            begin +            fail_on(URI::InvalidURIError) do                uri = URI.parse(path)                request.env["rack.url_scheme"] = uri.scheme || "http"                request.host = uri.host if uri.host                request.port = uri.port if uri.port                request.path = uri.path.to_s.empty? ? "/" : uri.path -            rescue URI::InvalidURIError => e -              raise ActionController::RoutingError, e.message              end            else              path = "/#{path}" unless path.first == "/" @@ -208,11 +201,21 @@ module ActionDispatch            request.request_method = method if method -          params = @routes.recognize_path(path, { :method => method, :extras => extras }) +          params = fail_on(ActionController::RoutingError) do +            @routes.recognize_path(path, { :method => method, :extras => extras }) +          end            request.path_parameters = params.with_indifferent_access            request          end + +        def fail_on(exception_class) +          begin +            yield +          rescue exception_class => e +            raise MiniTest::Assertion, e.message +          end +        end      end    end  end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index ea1ed20f3c..5f9c3bbf48 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -39,7 +39,6 @@ module ActionDispatch        # The selector may be a CSS selector expression (String), an expression        # with substitution values (Array) or an HTML::Selector object.        # -      # ==== Examples        #   # Selects all div tags        #   divs = css_select("div")        # @@ -58,7 +57,6 @@ module ActionDispatch        #     inputs = css_select(form, "input")        #     ...        #   end -      #        def css_select(*args)          # See assert_select to understand what's going on here.          arg = args.shift @@ -340,7 +338,6 @@ module ActionDispatch        # The content of each element is un-encoded, and wrapped in the root        # element +encoded+. It then calls the block with all un-encoded elements.        # -      # ==== Examples        #   # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)        #   assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do        #     # Select each entry item and then the title item @@ -401,8 +398,6 @@ module ActionDispatch        # You must enable deliveries for this assertion to work, use:        #   ActionMailer::Base.perform_deliveries = true        # -      # ==== Examples -      #        #  assert_select_email do        #    assert_select "h1", "Email alert"        #  end @@ -413,7 +408,6 @@ module ActionDispatch        #       # Work with items here...        #    end        #  end -      #        def assert_select_email(&block)          deliveries = ActionMailer::Base.deliveries          assert !deliveries.empty?, "No e-mail in delivery list" diff --git a/actionpack/lib/action_dispatch/testing/assertions/tag.rb b/actionpack/lib/action_dispatch/testing/assertions/tag.rb index 5c735e61b2..68f1347e7c 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/tag.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/tag.rb @@ -48,8 +48,6 @@ module ActionDispatch        # * if the condition is +true+, the value must not be +nil+.        # * if the condition is +false+ or +nil+, the value must be +nil+.        # -      # === Examples -      #        #   # Assert that there is a "span" tag        #   assert_tag :tag => "span"        # @@ -104,7 +102,6 @@ module ActionDispatch        # Identical to +assert_tag+, but asserts that a matching tag does _not_        # exist. (See +assert_tag+ for a full discussion of the syntax.)        # -      # === Examples        #   # Assert that there is not a "div" containing a "p"        #   assert_no_tag :tag => "div", :descendant => { :tag => "p" }        # | 
