RSpec in Rails: How to skip a before_filter?
To skip the before filter:
controller.class.skip_before_filter :name_of_method_used_as_before_filter
The one caveat (mentioned the docs) is that this will only work for method-reference filters, not procs.
Alternatively, you could stub current_user.has_role?
describe SomeModelsController, "GET to index (functional)" do before(:each) do controller.current_user.stub!(:has_role?).and_return(true) end it "should find all Models" do Model.should_receive(:find).with(:all) endend
Old question, but I had to solve this just recently. This will only work for Rails 3.1, for earlier versions you should replace _process_action_callbacks
with filter_chain
(untested)
You can simply delete a matching Proc from the filter chain like so (Test::Unit example):
class RandomControllerTest < ActionController::TestCase def setup @controller.class._process_action_callbacks.each do |f| @controller.class._process_action_callbacks.delete(f) if f.raw_filter.to_s.match(/**<match for your proc>**/) end endend
How about just not doing a GET request?Try calling the controller method by itself.
controller.index