Stumped on body: syntax #314

Closed
mrjcleaver opened this Issue Oct 14, 2013 · 4 comments

Projects

None yet

2 participants

@mrjcleaver

I really apologize if this is a stupid question, but it's had me stumped for too long.

Given my code:

    WebMock.should have_requested(:post, "http://****.com/rest/api/latest/issue/LE-27") .with(body: {"jql" => "Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'"})

And that the following requests were made:

   POST http://*****.com/rest/auth/latest/session with body '{"username":"automation","password":"*****"}' with headers {'Content-Type'=>'application/json'} was made 1 time
   POST http://****.com/rest/api/latest/search with body '{"jql":"Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'","startAt":0,"maxResults":50,"fields":["*navigable"]}' with headers {'Content-Type'=>'application/json', 'Cookie'=>'JSESSIONID=651F5ADB8B2D42C3D0D6067EAE42BA07'} was made 1 time
 ... a bunch more...

Why do I get:
Failure/Error: Unable to find matching line from backtrace

   The request POST http://****.com/rest/api/latest/issue/LE-27 with body {"jql"=>"Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'"} was expected to execute 1 time but it executed 0 times

It seems to not match '{"jql":"Se...' with {"jql"=>"Se... but for all the string escaping variations I have tried I am at a loss to find how to make them line up.

Thanks for any help!
Martin.

@bblimke
Owner

From the output you provided, WebMock tells you that there was a request made to "http://*.com/rest/api/latest/search" and you are expecting request made to "http://*.com/rest/api/latest/issue/LE-27".

@mrjcleaver

Well, thank you. That's true. Was staring too long.

Still, the problem remains - now I get:

With code:

    WebMock.should have_requested(:post, "http://****.com/rest/api/latest/search")
                   .with(body: {"jql" => "Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'",
                                "startAt" => "0",
                                "maxResults" => "50",
                                "fields" => ["*navigable"]
                          }
                   )

Message:

   Failure/Error: Unable to find matching line from backtrace
   The request POST http://****.com/rest/api/latest/search with body {"jql"=>"Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'", "startAt"=>"0", "maxResults"=>"50", "fields"=>["*navigable"]} was expected to execute 1 time but it executed 0 times

   The following requests were made:
   ....       
   POST http://****.com/rest/api/latest/search with body '{"jql":"Server ~ '__FILE__' AND 'Bug Reference' ~ 'https://****.com/browse/'","startAt":0,"maxResults":50,"fields":["*navigable"]}' with headers {'Content-Type'=>'application/json', 'Cookie'=>'JSESSIONID=41FEB176E99C6A868690B72FA18E697C'} was made 1 time
   ....

?

@bblimke
Owner

You need to stare a little longer :) startAt and maxResults are integers not strings.

@mrjcleaver

Thank you very much Bartosz! Works a treat.

@mrjcleaver mrjcleaver closed this Oct 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment