rspec-rails (2.8.1) を使用して、永続化のために mongoid (3.4.7) を使用して Rails 3.1 アプリの機能をテストしています。匿名コントローラーのrspec-railsドキュメントで実行できることが示唆されているのと同じ方法で、ApplicationControllerでMongoid::Errors::DocumentNotFoundエラーのrescue_fromをテストしようとしています。しかし、次のテストを実行すると...
require "spec_helper"
class ApplicationController < ActionController::Base
rescue_from Mongoid::Errors::DocumentNotFound, :with => :access_denied
private
def access_denied
redirect_to "/401.html"
end
end
describe ApplicationController do
controller do
def index
raise Mongoid::Errors::DocumentNotFound
end
end
describe "handling AccessDenied exceptions" do
it "redirects to the /401.html page" do
get :index
response.should redirect_to("/401.html")
end
end
end
次の予期しないエラーが発生します
1) ApplicationController handling AccessDenied exceptions redirects to the /401.html page
Failure/Error: raise Mongoid::Errors::DocumentNotFound
ArgumentError:
wrong number of arguments (0 for 2)
# ./spec/controllers/application_controller_spec.rb:18:in `exception'
# ./spec/controllers/application_controller_spec.rb:18:in `raise'
# ./spec/controllers/application_controller_spec.rb:18:in `index'
# ./spec/controllers/application_controller_spec.rb:24:in `block (3 levels) in <top (required)>'
なんで?このモンゴイドエラーを発生させるにはどうすればよいですか?