現在、rspecを使用してカスタムDeviseセッションコントローラをテストしようとしています。私のコントローラは、次のようになります。AbstractController :: ActionNotFoundでカスタムDeviseセッションコントローラのRSpecテストが失敗する
class SessionsController < Devise::SessionsController
def create
#valid email?
if !(params[:email] =~ /^[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,}$/)
set_flash_message :notice, "Please enter a valid e-mail address!"
end
super
end
end
マイRSpecのコントローラテストはこれです:
require 'spec_helper'
require 'devise/test_helpers'
describe SessionsController do
it "should put a warning on invalid mail address login attempt" do
post :create, :user => {:email => 'invalidEmailAddress'}
response.should contain "Please enter a valid e-mail address!"
end
it "should put no warning on valid mail address login attempt" do
pending
end
end
私はRSpecのテストを実行する場合は、次の行で失敗しますから
Failure/Error: post :new, :user => {:email => 'invalidEmailAddress'}
AbstractController::ActionNotFound
# ./spec/controllers/sessions_controller_spec.rb:7
のヒントplataformatec Devise Wikiとthis postはこの問題を解決しませんでした。ご協力いただきありがとうございます。私はさらに調査
追加
。私は実際には、コントローラの仕様を次のように加えて、エラーを「取り除く」ことができました:
before(:each) do
request.env['devise.mapping'] = Devise.mappings[:user]
end
しかし、今、新しいエラーが表示されます。
Failure/Error: post :create #currently fails with multiple render warning
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
でも継承に取り残さ作成する方法とコントローラにエラーが表示されます。エラーはget:newなどには表示されません。それは投稿のようです:作成のみ。 私はアイデアがありませんか?どんな助け? ありがとう! [:ユーザー]
'render'はビュー仕様用です - デフォルトではビューをレンダリングしないコントローラ仕様では意味をなさない。テストコントローラにレンダリングさせたい場合は、 'render_views'ディレクティブ(古い「integrate_views」を置き換えます)があります。 – zetetic
さて、そうです。しかし明示的なレンダリングがなくてもエラーが発生します。私の古いコードでレンダリングに到達したことはありません。 – kaihowl
あなたの答えをありがとう。私はあなたの提案を試みましたが、誰も私のために働いていませんでした。残念なことに、同じエラーが何度も繰り返し現れます。 – kaihowl