2

我正在使用清扫器清除片段缓存,并且在开发中一切正常,但我在我们的规范中收到错误

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")

有人知道为什么它可能找不到该方法吗?

4

1 回答 1

0

好的,似乎这里最好的策略是像这样在 spec_helper.rb 中存根方法

RSpec.configure do |config|
  config.before(:each) do
    NavigationSweeper.any_instance.stub(:expire_fragment)
  end
end
于 2014-04-10T20:52:29.673 回答