मैं वर्तमान में ककड़ी सीखने और इसे ठीक से उपयोग करने का प्रयास कर रहा हूं। सर्वोत्तम प्रथाओं की खोज करते समय अधिकांश पुराने तरीके का वर्णन किया गया है और मुझे वास्तव में एक अच्छी मार्गदर्शिका नहीं मिली है। मैंने इसे करने के नए तरीके के बारे में पढ़ा लेकिन मुझे सर्वोत्तम अभ्यास के साथ कुछ समस्याएं हैं।रेल के लिए ककड़ी कैसे लिखें (सर्वश्रेष्ठ अभ्यास)। फ़ीचर और चरण
निम्नलिखित कुछ बुनियादी ककड़ी परिदृश्य है जो मैं काम कर रहा हूं।
Scenario: Unsuccessful login
Given a user has an account
When the user tries to log in with invalid information
Then the user should see an log in error message
Scenario: Successful login
Given a user has an account
When the user logs in
Then the user should see an log in success message
And the user should see a sign out link
Scenario: Successful logout
Given a signed in user
Then the user logs out
And the user should see an log out success message
मुझे आश्चर्य है कि यह ठीक है या नहीं? मुझे समस्याएं हैं यदि मुझे इसे "आई विज़िट" या "यूजर विज़िट" या "वह विज़िट" के रूप में लिखना चाहिए, मूल रूप से क्या पसंद किया जाता है?
दूसरी बात मुझे आश्चर्य है कि कैसे मैं निम्नलिखित तैयार करना चाहिए:
Scenario: Visit profile of user
Given a user
And a second user
When the user visit the user profile
Then the user should see the name of the user
Scenario: Visit profile of another user
Given a user
And a second user
When the user visit the second users profile
Then the user should see the name of the second user
यह सिर्फ कुछ मैं एक साथ रखा है, लेकिन मुझे लगता है कि यह सबसे अच्छा तरीका नहीं है। मैं अपनी चरण परिभाषा फ़ाइलों में समस्याओं में भाग लेता हूं। परिदृश्यों को संभालने के लिए आप चरणों को कैसे परिभाषित करेंगे? मैं कुछ और सामान्य लिखना चाहता था, लेकिन शायद यह वास्तव में संभव नहीं है? क्या मेरे पास @second_user विशेषता है या आप क्या सुझाव देते हैं?
def user
@user ||= FactoryGirl.create :user
end
Given /^a signed in user$/ do
user
sign_in(@user.email, @user.password)
end
Given /^a user has an account$/ do
user
end
When /^the user logs in$/ do
sign_in(@user.email, @user.password)
end
When /^the user logs out$/ do
click_link ('Sign out')
end
When /^the user tries to log in with invalid information$/ do
sign_in("incorrect-email", "incorrect-password")
end
Then /^the user should see a sign out link$/ do
page.should have_link('Sign out')
end
Then /^the user should see an log in success message$/ do
should have_success_message('Signed in successfully.')
end
When /^the user should see an log out success message$/ do
should have_success_message('Signed out successfully.')
end
Then /^the user should see an log in error message$/ do
should have_error_message('Invalid email or password.')
end
मेरी मदद करने के लिए धन्यवाद!
धन्यवाद होगा। ऐसा लगता है कि मॉडल और ककड़ी सुविधाओं के बीच कुछ युग्मन जोड़ने के आसपास कोई रास्ता नहीं है। मेरी आशा थी कि उपयोगकर्ता नाम जैसी कोई भी जानकारी न हो: मेरी सुविधाओं में लेकिन ऐसा लगता है कि इसके चारों ओर कोई अच्छा तरीका नहीं है। –
आपका स्वागत है, मुझे लगता है कि युग्मन होने पर कुछ भी गलत नहीं है, इसलिए हम परीक्षण लिखते हैं। उदाहरण के लिए, यदि आप उपयोगकर्ता मॉडल को उपयोगकर्ता नाम फ़ील्ड नहीं बदलते हैं तो यह परिदृश्य विफल हो जाता है जो होने वाला है , और फिर आप मॉडल को ठीक करेंगे या परिदृश्य को बदल देंगे। – Khaled