我有一个控制器如下。
class AdminsController < ApplicationController
before_filter :authenticate_admin!, except: [:forgot_password]
end
具有期望条件的过滤器之前的rspec是什么
我确实喜欢这个
describe 'response of filters' do
describe 'there are no authentication required ' do
it "before forgot_password" do
controller.stub(:action_name){ :forgot_password }
should_not use_before_filter(:authenticate_admin!)
end
end
end
end
但我收到如下错误
Failure/Error: should_not use_before_filter(:authenticate_admin!)
Expected that AdminsController would not have :authenticate_admin! as a before_filter
答案 0 :(得分:1)
我查看了文档,很明显,shoulda-matchers不支持条件前过滤器。
我通常不会在之前测试过滤器。我有两种方法:
所以在你的情况下,我会做类似
的事情require 'spec_helper'
describe AdminsController do
it { should use_before_filter(:authenticate_admin!) }
it "allows unauthenticated access for forgot_password" do
controller.should_not_receive(:authenticate_admin!)
get :forgot_password
end
end