जवाबों:
दस्तावेज़ ढूंढना आसान नहीं है, लेकिन आप एक हैश के साथ उदाहरणों को टैग कर सकते हैं। उदाहरण के लिए।
# spec/my_spec.rb
describe SomeContext do
it "won't run this" do
raise "never reached"
end
it "will run this", :focus => true do
1.should == 1
end
end
$ rspec --tag focus spec/my_spec.rb
GitHub पर अधिक जानकारी । (बेहतर लिंक वाला कोई भी व्यक्ति, कृपया सलाह दें)
(अपडेट करें)
RSpec अब यहाँ शानदार दस्तावेज है । देखें --tag विकल्प जानकारी के लिए खंड।
V2.6 के रूप में इस तरह के टैग को कॉन्फ़िगरेशन विकल्प को शामिल करके और भी अधिक व्यक्त किया जा सकता है treat_symbols_as_metadata_keys_with_true_values, जो आपको करने की अनुमति देता है:
describe "Awesome feature", :awesome do
जहां :awesomeमानो इलाज किया गया था :awesome => true।
आरएसईपी को कॉन्फ़िगर करने के तरीके के लिए यह उत्तर भी देखें कि स्वचालित रूप से 'केंद्रित' परीक्षण चलाने के लिए। यह विशेष रूप से गार्ड के साथ अच्छी तरह से काम करता है ।
:focus, जो कि अवांछनीयता जैसे 'बाइंडिंग.प्री कंसोल.लॉग' , , आदि को रेंगने से लेकर कोडबेस तक जाने से रोकता है ।
rspecकार्यक्रम के उपयोग और वास्तविक व्यवहार का वर्णन करता है :) क्योंकि रिलेश डॉक नहीं करता है।
आप वे सभी परीक्षण चला सकते हैं जिनमें एक विशिष्ट स्ट्रिंग --example (या -e) विकल्प होता है :
rspec spec/models/user_spec.rb -e "User is admin"
मैं उस एक का सबसे अधिक उपयोग करता हूं।
अपने में spec_helper.rb:
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
और फिर अपने चश्मे पर:
it 'can do so and so', focus: true do
# This is the only test that will run
end
आप 'फिट' के साथ परीक्षण पर भी ध्यान केंद्रित कर सकते हैं या 'xit' के साथ बाहर कर सकते हैं, जैसे:
fit 'can do so and so' do
# This is the only test that will run
end
config.filter_run_when_matchingऔर यह सिर्फ :focusउदाहरण के लिए जोड़कर काम कर सकता है
वैकल्पिक रूप से आप लाइन नंबर को पास कर सकते हैं: rspec spec/my_spec.rb:75- लाइन नंबर एक एकल युक्ति या एक संदर्भ को इंगित कर सकता है / वर्णन ब्लॉक (उस ब्लॉक में सभी चश्मा चला रहा है)
आप कोलन के साथ कई लाइन नंबरों को भी स्ट्रिंग कर सकते हैं:
$ rspec ./spec/models/company_spec.rb:81:82:83:103
आउटपुट:
Run options: include {:locations=>{"./spec/models/company_spec.rb"=>[81, 82, 83, 103]}}
RSpec 2.4 के रूप में (मुझे लगता है) आप एक पहले जोड़ें कर सकते हैं fया xकरने के लिए it, specify, describeऔर context:
fit 'run only this example' do ... end
xit 'do not run this example' do ... end
http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#fit-class_method http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#xit-class_method
होना सुनिश्चित करें config.filter_run focus: trueऔर config.run_all_when_everything_filtered = trueअपने में spec_helper.rb।
RSpec के नए संस्करणों में, समर्थन को कॉन्फ़िगर करना और भी आसान है fit:
# spec_helper.rb
# PREFERRED
RSpec.configure do |c|
c.filter_run_when_matching :focus
end
# DEPRECATED
RSpec.configure do |c|
c.filter_run focus: true
c.run_all_when_everything_filtered = true
end
देख:
https://relishapp.com/rspec/rspec-core/docs/filtering/filter-run-when-matching
https://relishapp.com/rspec/rspec-core/v/3-7/docs/configuration/run-all-when-everything-filtered
इसके अलावा आप उन चश्मे को चला सकते हैं जो focus: trueडिफ़ॉल्ट रूप से हैं
कल्पना / spec_helper.rb
RSpec.configure do |c|
c.filter_run focus: true
c.run_all_when_everything_filtered = true
end
फिर बस चलाते हैं
$ rspec
और केवल केंद्रित परीक्षण चलाया जाएगा
तब जब आप focus: trueसभी परीक्षणों को अच्छी तरह से हटा दें तो फिर से चलाएं
अधिक जानकारी: https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/filtering/inclusion-filters
spec/spec_helper.rbहमेशा शामिल? या केवल अगर कोई विकल्प नहीं दिया जाता है? परीक्षण मॉड्यूल क्यों हैं require 'spec_helber', और उपरोक्त कोड में फ़ाइल को निर्दिष्ट करके एकल परीक्षण चलाने की संभावना को समाप्त नहीं किया गया है? मुझे इस पर कोई दस्तावेज नहीं मिल रहा है।
spec_helper.rbहमेशा अगर आपके पास भी शामिल है --require spec_helperमें .rspecपरियोजना जड़ में।
आप के रूप में चला सकते हैं rspec spec/models/user_spec.rb -e "SomeContext won't run this"।