1

I would like to use the same uri with different request params, how can I do this? The following example seems does not work (

  stub_request(:post, "http://tests/1/users/create").
      with({email: 'wrong_format'}).
      to_return(status: 400, body: {msg: 'Bad request'}.to_json, headers: {})

  stub_request(:post, "http://tests/1/users/create").
      with(email: "test@mail.com").
      to_return(status: 200, body: {msg: 'Thanks for signing up for us'}.to_json, headers: {})
Aydar Omurbekov
  • 2,047
  • 4
  • 27
  • 53

2 Answers2

0

From what the documentation says, the with-clauses are not correct (you should use body: { email: "foo@bar.de" } or something similar).

Docs here!

jfornoff
  • 1,368
  • 9
  • 15
0

According to the docs, this is accomplished by adding a sequence of return hashes:

stub_request(:get, "www.example.com").
  to_return({body: "abc"}, {body: "def"})
Net::HTTP.get('www.example.com', '/')    # ===> "abc\n"
Net::HTTP.get('www.example.com', '/')    # ===> "def\n"
Jesse Clark
  • 1,150
  • 2
  • 13
  • 15