मेरे पास एक सरल नियंत्रक परीक्षण है, जिसमें ए.ओ. है। निम्नलिखित कोड:rspec नियंत्रकों परीक्षण को तेज़ करना: सभी विफल होने से पहले उपयोग करना?
context "POST :create" do
before (:each) do
post :create, :user_id => @user.id,
:account => { .. some data ... }
end
it { response.status.should == 201 }
it { response.location.should be_present }
end
अब मैं एक बहुत ही आसान तरीका के बारे में सोचा इस परीक्षण में तेजी लाने के लिए, और एक before(:each)
के बजाय एक before(:all)
उपयोग करने के लिए। उस स्थिति में पोस्ट केवल एक बार किया जाएगा।
तो मैं ने लिखा है:
context "POST :create" do
before (:all) do
post :create, :user_id => @user.id,
:account => { .. some data ... }
end
it { response.status.should == 201 }
it { response.location.should be_present }
end
लेकिन तब मैं निम्नलिखित त्रुटियाँ मिलती है:
RuntimeError:
@routes is nil: make sure you set it in your test's setup method.
इस डिजाइन से है? क्या इसे रोकने का कोई तरीका है?
describe PagesController do
describe "GET 'index'" do
before(:each) do
@@response ||= begin
get :index
response
end
end
it { @@response.should redirect_to(root_path) }
it { @@response.status.should == 301 }
it { @@response.location.should be_present }
end
end
क्या आपको इसका समाधान मिला है? मैंने एक ही मुद्दे में भाग लिया है। – ktusznio