mercredi 18 juillet 2018

dynamic parameters for post method in webmock

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: {})

Aucun commentaire:

Enregistrer un commentaire