1

I'm trying to mock some requests which have dynamic parameters and they constantly change each time I ran the tests!

Is there any way I could set parameters with variables?

for Get method you can set template but nothing for Post!

body = {
    "id":"#{user_id}",
    "type":["User","ActiveRecord::Base"],
    "class_name":"User",
    "email_text":"user@example.com",
  }.to_json

  stub_request(:post, "http://solr/test/update?wt=json").
         with(
           body: "[#{body}]",
           headers: {
          'Accept'=>'*/*',
          'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
          'Content-Type'=>'application/json',
           }).to_return(status: 200, body: "", headers: {})

any user_id should be acceptable

mehrnoush
  • 11
  • 3
  • Did you try `body: body,`? Where body is variable name you have defined? – Manwal Jul 18 '18 at 07:36
  • that's the right formate i should mock! the problem is that user_id changes each time i ran my tests and it gets random numbers – mehrnoush Jul 18 '18 at 07:48

0 Answers0