How to set env ['SERVER_NAME'] in a rack / test?

Sinatra env['SERVER_NAME'] tests use www.example.com by default. How can I install this in some arbitrary domain?

Capybara has a .default_host method but does not use Capybara.

Or is it possible to change env [ DEFAULT_HOST ]?

Using RSpec, Sinatra, WebMock.

EDIT: adding env['SERVER_NAME'] = 'www.foo.com' to RSpec checks for an exception:

NameError: undefined local variable or method 'env' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe6ce3b5ff8>

+4
source share
1 answer

The env helper is only available in the Sinatra app.

One way to change this is to make a request:

 get "/blah", {}, {'HTTP_SERVER_NAME' => 'www.foo.com' } 

The third argument to the get / post stand / test is the hash of the headers.

+4
source

All Articles