我试图用rspec在我的current_user(使用修改后的restful_authentication auth解决方案)上剔除方法。我完全不确定如何在我的控制器规格中访问此方法。 current_user本身不起作用。我需要首先获得控制器吗?我该怎么做呢?RSpec访问application_controller方法,如'current_user'
使用rails 2.3.5
,rspec 1.3.0
和rspec-rails 1.3.2
# my_controller_spec.rb
require 'spec_helper'
describe MyController do
let(:foos){ # some array of foos }
it "fetches foos of current user" do
current_user.should_receive(:foos).and_return(foos)
get :show
end
end
主要生产
NoMethodError in 'ChallengesController fetches foos of current user'
undefined method `current_user' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1::Subclass_2::Subclass_2:0x7194b2f4>
真棒,我会测试此提到,顺便说一句,什么是'之间的区别stub'和'stub!' – brad 2010-09-16 12:26:30
None - 'stub'是'stub!'的别名,所以它们可互换 – zetetic 2010-09-16 16:56:18
工作! thx一堆 – brad 2010-09-21 14:32:09