我想创建一些特别的存根方法stub_check
并stub_chain_check
确保该方法存在。
例如:
#spec/controllers/payments_controller_spec.rb`
describe PaymentsController do
it "makes a payment" do
# Ensure method exists, Payment.new.respond_to?(:pay)
# the API of Payment can change and tests will pass
raise "Stubbing wrong method Payment#pay method doesn't exists" unless Payment.new.respond_to?(:pay)
Payment.any_instance.stub(pay: true) # We can stub method now
# Code...
end
end
但我想像Payment.stub_check(pay: true)