【发布时间】:2011-02-08 21:06:28
【问题描述】:
我正在为一个插件编写规范,该插件具有用户可以选择加载的不同模块。 其中一些模块会动态地将 before_filters 添加到 ApplicationController。
问题有时是,如果模块 X 的规范运行并添加了一个 before_filter,那么稍后运行的模块 Y 的规范将失败。我需要以某种方式在 clean ApplicationController 上运行第二个规范。
有没有办法在过滤器之前删除或在规范之间完全重新加载 ApplicationController?
例如在以下规范中,第二个“它”没有通过:
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
【问题讨论】:
标签: ruby-on-rails rspec before-filter