このクラスをテストする方法を考えています。そのインターフェイスは、RecurlyAPIをラップするadd_propertyとremove_propertyの2つのメソッドのみを公開します。
class SubscriptionManager
def initialize(account_code)
@account_code = account_code
end
def add_property
subscription.update_attributes subscription_add_ons: [{ add_on_code: 'property', quantity: property_count + 1 }]
end
def remove_property
subscription.update_attributes subscription_add_ons: [{ add_on_code: 'property', quantity: property_count - 1 }]
end
private
def property_count
subscription.add_ons.first[:quantity]
end
def subscription
@subscription ||= Recurly::Subscription.find(@account_code)
end
end
これが私が書き込もうとしているテストの概要ですが、Recurly gemは独自のテストセットを備えた優れたラッパーを提供するため、ここでの私の目標はAPIをヒットしないことです。しかし、私はAPIを押すことによってのみこれを行うことができると思い始めています。誰かアイデアはありますか?
describe SubscriptionManager do
subject { SubscriptionManager.new('1') }
before do
subscription = mock 'Subscription'
Recurly::Subscription.stub(:find).with('1').and_return subscription
end
describe 'add_property' do
it 'increases the quantity of the property add on' do
end
end
describe 'remove_property' do
it 'decreases the quanity of the property add on' do
end
end
end