Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

HttpMock often too strict in matching requests

#2002

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.

Reported by Michael Kintzer · February 18th, 2009 @ 01:41 AM

State: stale
Milestone: 3.x
Assigned to: Rick Rick
Importance: none

Activity

  1. Dan Pickett
    Dan Pickett

    +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.

    February 19th, 2009 @ 02:34 PM

  2. Dan Chak
    Dan Chak

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

    February 20th, 2009 @ 03:54 PM

  3. Michael Kintzer
    Michael Kintzer

    @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.

    February 20th, 2009 @ 08:14 PM

  4. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Rick
    • Tag changed from patch to http_mock, patch

    March 2nd, 2009 @ 05:43 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:54 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:54 PM