メソッドと仕様があります。
class Event
def self.renew_subscription(user)
subscription = user.subscription
result = subscription.renew
user.pay(subscription.plan.price_in_cents) if result
result
end
end
let!(:user) { create :user }
describe ".renew_subscription" do
before do
user.subscription.stub!(:renew).and_return(true)
user.subscription.stub!(:plan).
and_return(Struct.new("SP", :price_in_cents).new(699))
end
context "when have to pay" do
it "pays" do
user.should_receive(:pay)
Event.renew_subscription user
end
end
end
そこにユーザーbelongs_to :subscription
とサブスクリプションbelongs_to :plan
subscription.renew
and subscription.plan
(or )をスタブする方法はありsubscription.plan.price_in_cents
ますか?