तो मेरी कोड में मैं इस विधि मैं परीक्षण करने के लिए कोशिश कर रहा हूँ है:Rspec - तर्कों की गलत संख्या जब ऊपर उठाने त्रुटि
# checks if a file already exists on S3
def file_exists?(storage_key)
begin
s3_resource.bucket(@bucket).object(storage_key).exists?
rescue Aws::S3::Errors::Forbidden => e
false
end
end
अब मैं दो टेस्ट केस बनाने के लिए कोशिश कर रहा हूँ - जब फ़ाइल मौजूद है के लिए एक , और एक जब यह नहीं करता है।
विफलता मामले पर ध्यान केंद्रित करना। Aws::S3::Errors::Forbidden
त्रुटि को बढ़ाने के लिए मैं exists?
को स्टब करना चाहता हूं ताकि file_exists?
विधि गलत हो जाएगी।
it "returns false if the file doesn't already exist" do
allow_any_instance_of(Aws::S3::Object).to receive(:exists?).and_raise(
Aws::S3::Errors::Forbidden
)
expect(instance.file_exists?('foo')).to be false
end
इस परीक्षण मैं यह देख चल रहा है::
यहाँ की तरह क्या अपने परीक्षण कोड दिखाई देता है
wrong number of arguments (given 0, expected 2)
# ./lib/s3_client_builder.rb:48:in `file_exists?'
सच स्पष्ट नहीं यहाँ क्या हो रहा है, के बाद से file_exists?
विधि निश्चित रूप से नहीं है 2 की एक धैर्य और न ही exists?
विधि मैं stubbing कर रहा हूँ।
इसका निदान करने के लिए, मैंने begin
ब्लॉक में ब्रेकपॉइंट लगाया। मैं कोशिश करता हूं और <object>.exists?
लाइन चलाता हूं और एक ही त्रुटि प्राप्त करता हूं।