我有一PostDecorator
堂课app/decorators/post_decorator.rb
。它有一个调用 Devise 方法的current_user
方法。它看起来像这样:
class PostDecorator < Draper::Decorator
delegate_all
def voter
h.current_user
end
end
我有一个PostDecorator
规格spec/decorators/post_decorator_spec.rb
require 'spec_helper'
describe PostDecorator, type: :decorator do
let(:post) { FactoryGirl.create(:post) }
let(:user) { FactoryGirl.create(:user) }
before { allow(helper).to receive(:current_user) { user } }
describe 'voter' do
it 'returns the current_user' do
expect(post.voter).to eq user
end
end
end
当我运行它时,我得到一个未定义的方法错误:
<Draper::HelperProxy:0x007fb1c4f85890 ... does not implement: current_user
宝石版本:
- 布帘 (1.4.0)
- rspec-rails (3.4.1)
- 设计(3.5.5)
另外我应该注意我app/lib
目录中的所有内容都是自动加载的。在application.rb
我有config.autoload_paths << Rails.root.join('lib')