質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Q&A

0回答

1117閲覧

diviseのconfirmableでフィーチャスペックのテストを書きたい

sasa819

総合スコア7

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

0グッド

1クリップ

投稿2019/03/15 12:51

前提・実現したいこと

diviseでログイン機能を実装し、ユーザー登録時に入力したメールアドレスにメールを送信し、ユーザー認証をする機能を実装しました。
ブラウザ上ではメールが正しく送られ、ユーザー登録ができているのですが、フィーチャスペックでのテストを走らせるとエラーが出ます。

発生している問題・エラーメッセージ

Failure/Error: <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p> ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

該当のソースコード

spec/features/sign_up_spec.rb require 'rails_helper' feature 'Sign up' do scenario "ユーザー登録を行い、ログインするとユーザーの個別ページに遷移する" do visit root_path expect(page).to have_http_status :ok click_link "さっそく登録!" fill_in "メールアドレス", with: 'foo@example.com' fill_in "ユーザーネーム", with: 'sasa' fill_in "パスワード", with: 'test' fill_in "確認用パスワード", with: 'test' click_on 'ユーザー登録' expect(page).to have_content "本人確認用のメールを送信しました。メール内のリンクからアカウントを有効化させてください。" end end
ユーザー登録画面 <h2>ユーザー登録</h2> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> <div class="field"> <%= f.label :email %><br /> <%= f.email_field :email, autofocus: true, autocomplete: "email" %> </div> <div class="field"> <%= f.label :username %><br /> <%= f.text_field :username, class: "form-control" %> </div> <div class="field"> <%= f.label :password %> <% if @minimum_password_length %> <em>(<%= @minimum_password_length %>文字以上)</em> <% end %><br /> <%= f.password_field :password, autocomplete: "new-password" %> </div> <div class="field"> <%= f.label :password_confirmation %><br /> <%= f.password_field :password_confirmation, autocomplete: "new-password" %> </div> <div class="actions"> <%= f.submit "ユーザー登録" %> </div> <% end %> <%= render "devise/shared/links" %>

試したこと

configのhostのリンクはもともと記載してあります。

config.action_mailer.default_url_options = { host: 'localhost:3001' }

どなたか対応策を宜しくお願い致します。。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問