In Sinatra tests, env['SERVER_NAME']
defaults to www.example.com
. How can I set this to some arbitrary domain?
Capybara has .default_host
method, but not using Capybara.
Or, is it possible to change the env[DEFAULT_HOST
]?
Using RSpec, Sinatra, WebMock.
EDIT: Adding env['SERVER_NAME'] = 'www.foo.com'
to RSpec test raises exception:
NameError: undefined local variable or method 'env' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe6ce3b5ff8>
The env
helper is only accessible within a Sinatra app.
One way to change it is when making a request:
get "/blah", {}, {'HTTP_SERVER_NAME' => 'www.foo.com' }
The 3rd argument of a rack/test get
or post
is the headers hash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With