आरएसपीसी & कैपिबरा के साथ काम करना, मुझे एक दिलचस्प परीक्षण विफलता मोड मिल रहा है जो परीक्षण मामले में लाइनों के कुछ सूक्ष्म पुनर्गठन के साथ चला जाता है ... सामान जो इससे कोई फर्क नहीं पड़ता।फैक्टरी गर्ल/कैपिबरा डेटाबेस मध्य परीक्षण से रिकॉर्ड हटाना?
मैं अपनी खुद की प्रमाणीकरण प्रणाली विकसित कर रहा हूं। यह वर्तमान में काम कर रहा है और मैं ब्राउज़र और सत्र कार्य आदि के साथ लॉगिन/आउट कर सकता हूं। हालांकि, इसका परीक्षण करने की कोशिश करना असफल रहा है। कुछ ऐसा हो रहा है कि मैं समझ में नहीं आता, जो कि (प्रतीत होता है) असंबंधित कॉल के आदेश पर निर्भर करता है।
require 'spec_helper'
describe "Sessions" do
it 'allows user to login' do
#line one
user = Factory(:user)
#For SO, this method hashes the input password and saves the record
user.password! '2468'
#line two
visit '/sessions/index'
fill_in 'Email', :with => user.email
fill_in 'Password', :with => '2468'
click_button 'Sign in'
page.should have_content('Logged in')
end
end
जैसा कि, परीक्षण विफल रहता है ... लॉगिन विफल रहता है।
संपादित ApplicationController
मेंclass ApplicationController < ActionController::Base
helper :all
protect_from_forgery
helper_method :user_signed_in?, :guest_user?, :current_user
def user_signed_in?
!(session[:user_id].nil? || current_user.new_record?)
end
def guest_user?
current_user.new_record?
end
def current_user
@current_user ||= session[:user_id].nil? ? User.new : User.find(session[:user_id])
rescue ActiveRecord::RecordNotFound
@current_user = User.new
flash[:notice] = 'You\'ve been logged out.'
end
end
class SessionsController < ApplicationController
def login
user = User.where(:email=>params[:user][:email]).first
debugger ###
if !user.nil? && user.valid_password?(params[:user][:password])
#engage session
else
#run away
end
end
def logout
reset_session
redirect_to root_path, :notice => 'Logget Out.'
end
end
जोड़ने: उपयोगकर्ता डेटाबेस में जहाँ तक नियंत्रक का संबंध है नहीं डाला जा रहा है: 'डिबगर' डालने के बाद दोनों कल्पना और नियंत्रक मैं देख सकता हूँ क्यों कॉल
कंसोल में, इसके बाद के संस्करण ब्रेकप्वाइंट पर:
1.9.2 [email protected]:~/Sites/website$ rspec spec/controllers/sessions_controller_spec.rb
/Users/vox/Sites/website/app/controllers/sessions_controller.rb:7
if !user.nil? && user.valid_password?(params[:user][:password])
(rdb:1) irb
ruby-1.9.2-p180 :001 > User.all.count
=> 0
ruby-1.9.2-p180 :002 >
हालांकि, अगर मैं अपने परीक्षण की कुछ पंक्तियों को पुनर्व्यवस्थित, रेखा से ऊपर 'एक' लाइन 'दो' डाल:
+०१२३५१६४१०६१ संक्षिप्तता की खातिर मैं उपयोगकर्ता ऑब्जेक्ट की सामग्री से भरा डंप हटा दिया है के लिए1.9.2 [email protected]:~/Sites/website$ rspec spec/controllers/sessions_controller_spec.rb
/Users/vox/Sites/website/app/controllers/sessions_controller.rb:7
if !user.nil? && user.valid_password?(params[:user][:password])
(rdb:1) irb
ruby-1.9.2-p180 :001 > User.all.count
=> 1
लेकिन मैं आपको विश्वास दिलाता कर सकते हैं:
describe "Sessions" do
it 'allows user to login' do
#line two
visit '/sessions/index'
#line one
user = Factory(:user)
#For SO, this method hashes the input password and saves the record
user.password! '2468'
fill_in 'Email', :with => user.email
fill_in 'Password', :with => '2468'
click_button 'Sign in'
page.should have_content('Logged in')
end
end
मैं कंसोल में इस मिल (समान ब्रेकप्वाइंट के रूप में ऊपर) कि परीक्षण अपेक्षित के रूप में पूरा करता है।
पास करने के लिए परीक्षा प्राप्त करने के लिए स्वैपिंग लाइनों का यह व्यवहार वास्तव में मेरे आदेशों के साथ क्या चल रहा है इसके बारे में मेरे विचार के साथ अच्छा नहीं है और अन्य क्षेत्रों में मेरे परीक्षण के लिए काफी सहनशील साबित हुआ है।
यहां क्या हो रहा है के बारे में कोई संकेत?
मैंने इस समस्या को प्रस्तुत करने वाले विचारों के लिए Google और SO को खराब कर दिया है, और आरएसपीसी/कैपिबारा और सत्रों के बारे में SO प्रश्नों की कोई कमी नहीं है। हालांकि कुछ भी ठीक फिट नहीं लग रहा था।
देखने के लिए धन्यवाद।
अद्यतन
मैं (सिर्फ एक यात्रा के कॉल करने से पहले) एक ब्रेकपाइंट जोड़ दिया है और परीक्षण करने के लिए कुछ डिबगिंग और इस के साथ वापस आ:
(rdb:1) user
#<User id: 1, login_count: 1, email: "[email protected]", encrypted_password: "11f40764d011926eccd5a102c532a2b469d8e71249f3c6e2f8b...", salt: "1313613794">
(rdb:1) User.all
[#<User id: 1, login_count: 1, email: "[email protected]", encrypted_password: "11f40764d011926eccd5a102c532a2b469d8e71249f3c6e2f8b...", salt: "1313613794">]
(rdb:1) next
/Users/vox/Sites/website/spec/controllers/sessions_controller_spec.rb:19
fill_in 'Email', :with => user.email
(rdb:1) User.all
[]
तो स्पष्ट रूप से रास्ते में कुछ ऐसा है जो यात्रा फैक्टरी गर्ल को बता रही है कि यह उपयोगकर्ता ऑब्जेक्ट के साथ किया गया है और इसलिए वह इसे हटा देती है?
संपादित करें test.log की सावधानीपूर्वक जांच करने के बाद, कुछ भी हटा नहीं रहा है। तो मैं वर्ग एक के लिए कम या ज्यादा वापस आ गया हूँ।
spec_helper.rb में स्थापित होना सबसे अच्छा है। – iltempo
यह मुझे पूरे दिन फंस गया था क्योंकि मुझे बहुत सारी परेशानियां थीं जिससे मुझे गलत रास्ता पड़ा। धन्यवाद! – Rimian