जैसे अनुप्रयोग_कंट्रोलर विधियों तक पहुंचने के लिए मैं अपने वर्तमान_यूसर (एक संशोधित restful_authentication auth समाधान का उपयोग कर) rspec के साथ एक विधि को बाहर करने की कोशिश कर रहा हूं। मैं पूरी तरह से अनिश्चित हूं कि मैं अपने कंट्रोलर चश्मा में इस विधि को कैसे एक्सेस कर सकता हूं। current_user स्वयं काम नहीं करता है। क्या मुझे पहले नियंत्रक को प्राप्त करने की आवश्यकता है? मैं यह कैसे करु?आरएसपीईसी '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>
भयानक, मैं इस बाहर का परीक्षण करेंगे उल्लेख controller.stub की जरूरत है, btw, 'के बीच क्या फर्क है स्टब 'और' स्टब! ' – brad
कोई नहीं - 'stub'' stub!' के लिए उपनाम है, इसलिए वे अदला-बदले – zetetic
काम कर रहे हैं! एक गुच्छा thx – brad