Skip to content

Instantly share code, notes, and snippets.

@kmeister2000
Created May 30, 2013 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmeister2000/311d1287a0caf6e21b5a to your computer and use it in GitHub Desktop.
Save kmeister2000/311d1287a0caf6e21b5a to your computer and use it in GitHub Desktop.
Stripe Payment Gateway Test (Minitest)
require 'test_helper'
describe PayingCustomer do
describe "without valid stripe_customer_id" do
it "saves the user and creates the Stripe Customer" do
user = MiniTest::Mock.new
customer = PayingCustomer.new(user)
user.expect(:save, true)
def customer.gateway
@gateway ||= MiniTest::Mock.new
end
customer.gateway.expect(:create, nil)
customer.save
assert user.verify
assert customer.gateway.verify
end
end
end
@marksim
Copy link

marksim commented May 30, 2013

Next piece of the refactor should probably be:

PayingCustomer.new(user, gateway)

Where we inject the gateway, but default to StripeGateway (or whatever) so we don't have to do the ugly "stubbing" thing in the middle.

This makes me think that stubbing is useful, but could point toward a problem with your design?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment