1

I'm using RSpec 3.5.0, and would like to enable HTTPS/SSL requests for all my specs.

Since I added force_ssl to my ApplicationController, all my specs are failing, since they are redirecting to the secure version of the site instead of rendering, etc.

elsurudo
  • 3,579
  • 2
  • 31
  • 48
  • 1
    Do you need to force SSL for all environments? You could omit test `force_ssl unless Rails.env.test?` or perhaps only force SSL for production: `force_ssl if Rails.env.production?` – james246 Nov 16 '16 at 13:18
  • That's true, I could do that. Still wondering if there is an answer to my original question, though. – elsurudo Nov 16 '16 at 13:27
  • You could set up your local environment to use a self-signed SSL certificate. http://stackoverflow.com/questions/34991868/how-can-i-setup-a-local-ssl-certificate-and-a-rails-application – james246 Nov 16 '16 at 13:33
  • Sure, but that doesn't solve my issue with testing – elsurudo Nov 16 '16 at 13:35
  • Does this help: http://stackoverflow.com/questions/6785261/test-an-https-ssl-request-in-rspec-rails – nathanvda Nov 16 '16 at 16:49
  • Yes I did see that, but that is only for one spec, and does not apply to all of them. For the `request.env['HTTPS']` method, I could apply this to all my specs easily, but that method is for an outdated version of RSpec... – elsurudo Nov 17 '16 at 08:30

1 Answers1

0

The suggestions here don't work under rails 5. If that's part of where you're stuck adding https! to your spec should work.

josnat
  • 11
  • 1
  • 1
  • how can that be done in the case of something like `expect(response).to redirect_to company_path(company)` ? (the error is `Expected response to be a redirect to but was a redirect to ` – Salomanuel Jan 04 '19 at 15:44