I'm writing specs for a plugin which has different modules that the user can choose to load. Some of these modules dynamically add before_filters to ApplicationController.
The problem is sometimes if the spec for module X runs and adds a before_filter, the spec for module Y which runs later will fail. I need somehow to run the second spec on a clean ApplicationController.
Is there a way to remove before filters or reload ApplicationController completely between specs?
For example in the following specs, the second 'it' does not pass:
describe ApplicationController do
context "with bf" do
before(:all) do
ApplicationController.class_eval do
before_filter :bf
def bf
@text = "hi"
end
def index
@text ||= ""
@text += " world!"
render :text => @text
end
end
end
it "should do" do
get :index
response.body.should == "hi world!"
end
end
context "without bf" do
it "should do" do
get :index
response.body.should == " world!"
end
end
end
You should be able to do this using context blocks to separate the two sets of examples.
The
before_filter
should only affect the examples in the "with module X" context.