我試圖用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