我正在使用清扫工来清除片段缓存,一切都在开发中正常工作,但我的规格中收到错误
2) Admin - Categories #index displays all categories
Failure/Error: create_basic_category_set
NoMethodError:
undefined method `expire_fragment' for #<NavigationSweeper:0x007fdc01a10970 @controller=nil>
# ./app/sweepers/navigation_sweeper.rb:5:in `after_save'
# ./spec/support/utilities.rb:21:in `create_basic_category_set'
# ./spec/features/admin/categories_spec.rb:5:in `block (2 levels) in <top (required)>'
这是清扫车
class NavigationSweeper < ActionController::Caching::Sweeper
observe Category, Product, Series
def after_save(record)
expire_fragment 'navigation'
end
end
这就是我在控制器中使用它的地方
class Admin::CategoriesController < Admin::BaseController
before_filter :set_up_nav_array
cache_sweeper :navigation_sweeper, only: [ :destroy, :update, :create, :update_positions ]
def index
@roots = Category.roots
end
这是规范(多个实例)失败的地方
pickers = FactoryGirl.create(:category, :name => "Pickers")
任何人都知道为什么它可能找不到那种方法?
答案 0 :(得分:0)
好的,这里最好的策略似乎是在spec_helper.rb
中存根这样的方法RSpec.configure do |config|
config.before(:each) do
NavigationSweeper.any_instance.stub(:expire_fragment)
end
end