Skip to content

Using the mock service with CORS

Beth Skurrie edited this page Jan 12, 2015 · 13 revisions

When you will be using CORS in real life

If your application will be making CORS requests in real life, then stub the OPTIONS request the way you would stub a normal request.

  some_provider
    .upon_receiving("a CORS request for /something")
    .with(method: 'options', path: '/something', headers: {
      'Access-Control-Request-Headers' => 'Content-Type',
      ....
    })
    .will_respond_with(
      status: 200,
      headers: {
        'Access-Control-Allow-Origin' => '....',
        'Access-Control-Allow-Headers' => 'Content-Type',
        'Access-Control-Allow-Methods' => 'PUT, POST....'
      }
    )

When you will not be using CORS in real life