This project is archived and is in readonly mode.

#2002 ✓stale
Michael Kintzer

HttpMock often too strict in matching requests

Reported by Michael Kintzer | February 18th, 2009 @ 01:41 AM | in 3.x

ActiveResource::HttpMock will raise InvalidRequestError when the incoming request does not exactly match the stubbed requests' path, method, and request headers.

Many times in testing however, the test is not concerned with the actual query-string portion of the path, or the specific request headers sent, but is more interested in stubbing a particular response or status for any request that is similar in nature. This often occurs with custom request methods such as:

/people/custom_method.xml?query_param_array%5Bname%5D=val

The url-encoding and query-string need to match exactly in the declaration of the HttpMock respond_to block, or the request path will not match.

I've attached a patch for HttpMock, and associated unit tests, that allows for specification of match_options :lax_path and :ignore_headers to reduce the burden on the test author in cases like this.

Comments and changes to this ticket

  • Dan Pickett

    Dan Pickett February 19th, 2009 @ 02:34 PM

    +1 on this idea. I've run into many headaches trying to mock index calls with different behaviors based on parameters I'm passing.

    I'm not sure of the option lax_path, as legacy tests will probably want the default behavior to remain unsensitive to parameters. Maybe something like :strict_uri, or :exact_uri

    Great idea.

  • Dan Chak

    Dan Chak February 20th, 2009 @ 03:54 PM

    Seems like a good idea and the patch looks good to me.

  • Michael Kintzer

    Michael Kintzer February 20th, 2009 @ 08:14 PM

    @Dan P. Thanks for the comment. I too would prefer the default behavior for path matching to not be concerned with parameters, but was hesitant to change the behavior in case legacy tests actually depend on a strict match.

  • Michael Koziarski

    Michael Koziarski March 2nd, 2009 @ 05:43 AM

    • Assigned user set to “Rick”
    • Tag changed from patch to http_mock, patch
  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:54 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:54 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages