Skip to content

Instantly share code, notes, and snippets.

@reggieb
Created July 10, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reggieb/d5fc57f616890cc34875fc0a4dd7db6f to your computer and use it in GitHub Desktop.
Save reggieb/d5fc57f616890cc34875fc0a4dd7db6f to your computer and use it in GitHub Desktop.
Using spys in rspec to mock connections to services
# Set up the spy object
let(:chargebee_site) { spy(ChargebeeSite) }
# Hook it into the work flow
before do
allow(ChargebeeSite).to receive(:new).and_return(chargebee_site)
end
# use `have_received` to test connection
it 'creates a chargebee coupon' do
subject
expect(chargebee_site).
to have_received(:create_coupon).
with(
id: customer.coupon,
name: customer.coupon,
meta_data: {
referrer_shopify_customer_id: customer.shopify_id
}.to_json
)
end
@reggieb
Copy link
Author

reggieb commented Jul 10, 2018

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