1
메서드가 존재하는지 확인하기 위해 몇 가지 특별한 스텁 메서드 stub_check
및 stub_chain_check
을 만들고 싶습니다. 예를 들어메서드가 Rspec에 있는지 확인하는 새 스텁 메서드를 만듭니다.
:
#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)
나는 그것에 대해 생각해 왔습니다. resourse.new.respond_to를 사용하는 좋은 아이디어가 아닌가? 메소드, 더 나은 resource.method_defined입니까? 방법,하지만 Payment.stub_check하고 싶습니다. –