RailsのコントローラのSSL・非SSLのときの振る舞いをテストするには request.env['HTTPS'] に 'on' か 'off' を代入すればいい。 describe SomeController do describe 'GET new' do context 'access using SSL' do before { request.env['HTTPS'] = 'on' } it do get :new # SSLでアクセスする end end context 'access not using SSL' do before { request.env['HTTPS'] = 'off' } # この中は非SSL end end end
![Rails+RspecでSSL・非SSLのテストするときはshared_context使うと捗る - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/e6f209df8916dfe5ea0ae3239861f8d1bcd224f5/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-412672c5f0600ab9a64263b751f1bc81.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9UmFpbHMlMkJSc3BlYyVFMyU4MSVBN1NTTCVFMyU4MyVCQiVFOSU5RCU5RVNTTCVFMyU4MSVBRSVFMyU4MyU4NiVFMyU4MiVCOSVFMyU4MyU4OCVFMyU4MSU5OSVFMyU4MiU4QiVFMyU4MSVBOCVFMyU4MSU4RCVFMyU4MSVBRnNoYXJlZF9jb250ZXh0JUU0JUJEJUJGJUUzJTgxJTg2JUUzJTgxJUE4JUU2JThEJTk3JUUzJTgyJThCJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnR4dC1jb2xvcj0lMjMxRTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmcz05ZTE2OGU4ZTQ1NzFlZjkzYjFjYTBhMDBiZTNjZjQ1YQ%26mark-x%3D142%26mark-y%3D57%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9NzcwJnR4dD0lNDB5dWt1X3QmdHh0LWNvbG9yPSUyMzFFMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT0zNiZ0eHQtYWxpZ249bGVmdCUyQ3RvcCZzPTA5ZjRhMWY2OWIzOWYxZDg0MGE2NmY3YzRkODA0ZGEz%26blend-x%3D142%26blend-y%3D486%26blend-mode%3Dnormal%26s%3Da696fbf544c94967c67bc86aa6ba7c91)