It looks like you might be using Rails, in which case you could do one of the following:
- To set "https" for all Rspec examples, create a file, such as spec/support/url_options.rb, that contains the following:
RSpec.configure do |config|
Rails.application.routes.default_url_options[:protocol] = 'https'
end
- To only target request specs, you could use a hook, such as:
RSpec.configure do |config|
config.before(:all, type: :request) do
Rails.application.routes.default_url_options[:protocol] = 'https'
end
end
- For a site-wide configuration, you could instead add the following to config/environments/test.rb:
Rails.application.configure do
default_url_options[:protocol] = 'https'
end
This should work fine for request specs, but there might be additional complications with feature specs. In that case, see https://github.com/rspec/rspec-rails/issues/1275.
If you're not using Rails, you could still follow the broad pattern above, but substitute your framework's equivalent method or configuration setting. If all else fails, you could override the Rspec methods get(), post(), etc. and in your overridden methods simply call super()
with { protocol: 'https' }
or { 'HTTPS' => 'on' }
merged into the arguments.
Also, note that 'HTTPS' => 'on'
may have been deprecated in favor of protocol: 'https'
.
Similar posts with additional possibilities:
Test an HTTPS (SSL) request in RSpec Rails
Simple way to test an HTTPS (SSL) request with RSpec
Force HTTPS/SSL for all controller/request specs in rspec