मैथ्यू बास एक महान मणि वह सिर्फ बात के इस प्रकार के लिए जारी है है की आवश्यकता होगी पारित करने के लिए प्राप्त करने के लिए। यह rspec matchers जोड़ता है जो यह सुनिश्चित करने के लिए जांच करता है कि सत्यापन वास्तव में अंतर्निहित ActiveRecord कोड को चलाने के बिना है। Read more about it here।
यह सत्यापन के लिए matchers जोड़ता है:
it_should_belong_to :employer
it_should_have_many :friends, :romans, :countrymen
it_should_have_one :account
it_should_have_and_belong_to_many :comments
और कुछ अन्य उपयोगी अतिरिक्त:
# tests that User.count increases by 1
it_should_be_createable :with => {:first_name => 'Ed', :last_name => 'The Duck', :email => '[email protected]'}
# tests that the attribute is protected
it_should_protect :email
किसी भी एक संपूर्ण नहीं है इसका मतलब है कि द्वारा
it_should_validate_presence_of :first_name, :last_name, :email
it_should_validate_numericality_of :zip
it_should_validate_uniqueness_of :email
it_should_validate_inclusion_of :gender, :in => %w(Male Female)
इसके अलावा संघों के लिए matchers सूची। मुझे एक कांटा मिला है जहां मैंने कुछ अन्य लोगों को जोड़ा है, शायद अन्य लोग भी चारों ओर तैर रहे हैं। यह एक अच्छा दृष्टिकोण है और मेरे लिए यह सुनिश्चित करने के लिए कि मध्यस्थता अभी भी मॉडल में थी, और यह सुनिश्चित करने के लिए ActiveRecord कोड निष्पादित करने के लिए परीक्षणों को स्पष्ट रूप से लिखना है।
स्रोत
2009-12-10 17:56:12
> मैं उनका परीक्षण करता हूं, क्योंकि मुझे नहीं लगता कि वे काम नहीं करते हैं, लेकिन यह सुनिश्चित करने के लिए कि –