Turnipでスクリーンショット取りたくてやってみたら出来たからメモです.
前提としてRails4.1以上でTurnipのテストができる状態になってることとします.
書き足したソース
RailsのAction Mailer Previewsはdevelopment
環境でしか使えないので自前でルートを追加.
config/routes.rb
if Rails.env.test?
get '/rails/mailers' , to: "rails/mailers#index"
get '/rails/mailers/*path', to: "rails/mailers#preview", as: 'mail_preview'
end
ついでにパスもspecに変更.
config/application.rb
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
最後に送信したメールを対象にプレビュー表示させておく.
spec/mailers/previews/test_mailer_preview.rb
class TestMailerPreview < ActionMailer::Preview
def last
ActionMailer::Base.deliveries.last
end
end
step
を以下のように書いておくとfeature
で開ける。
あとはスクリーンショットのステップをコールすればいい感じ。
spec/steps/mail_steps.rb
step %(最後に送信したメールを表示) do
url = mail_preview_path(path: 'test_mailer/last')
visit url
end
やろうとして諦めたこと
メールプレビューからメールヘッダのチェック等をするstep
プレビューのHTMLがシンプルすぎて諦めた.
メールプレビューから本文を使ったstep
本文部分がiframeだったので萎えて諦めた.
stackoverflowに取得の仕方が書いてあったけど未検証.
within_frame(find('<css rule>')) do
<code for dealing with iframe entries>
end