ruby on rails - Rspec for conditional filters -
i have 1 controller follow.
class adminscontroller < applicationcontroller before_filter :authenticate_admin!, except: [:forgot_password] end
what rspec before filters expect condition
i did
describe 'response of filters' describe 'there no authentication required ' "before forgot_password" controller.stub(:action_name){ :forgot_password } should_not use_before_filter(:authenticate_admin!) end end end end
but got error below
failure/error: should_not use_before_filter(:authenticate_admin!) expected adminscontroller not have :authenticate_admin! before_filter
i checked documentation, , clear shoulda-matchers not support conditional before-filters.
i not test before-filters that. have 2 approaches:
- or test can reach page when using specific user, , not another
- or test before-filter function called
so in case like
require 'spec_helper' describe adminscontroller { should use_before_filter(:authenticate_admin!) } "allows unauthenticated access forgot_password" controller.should_not_receive(:authenticate_admin!) :forgot_password end end
Comments
Post a Comment